Re: Passing a list of values to a function - Mailing list pgsql-general

From Matthew Peter
Subject Re: Passing a list of values to a function
Date
Msg-id 20060110041051.26971.qmail@web35215.mail.mud.yahoo.com
Whole thread Raw
In response to Re: Passing a list of values to a function  (Michael Fuhr <mike@fuhr.org>)
List pgsql-general
You could write the function to take an array of integers instead
of a text string:

CREATE OR REPLACE FUNCTION getlist(integer[]) RETURNS SETOF my_tbl as $$
SELECT * FROM my_tbl
WHERE u_id = 0 OR u_id = ANY($1)
$$ LANGUAGE SQL STABLE STRICT;

SELECT * FROM getlist('{1,2,3}');

Another way would be to build a query string in a PL/pgSQL function
and use EXECUTE, but beware of embedding function arguments in query
strings without quoting.

--
Michael Fuhr
Hmmmmmm .... I suspected it was using it as a text string, seeing how that's how it way defined. I guess querying it as an array would work okay.

Is there any way to blow out how the query was executed? Such as seeing all the WHERE joins and what not along with the explain output on the console? I think I read so mewhere about it showing in the logs or something?


Yahoo! Photos – Showcase holiday pictures in hardcover
Photo Books. You design it and we’ll bind it!

pgsql-general by date:

Previous
From: Matthew Peter
Date:
Subject: Re: plpgsql question
Next
From: Michael Fuhr
Date:
Subject: Re: Vacuum all tables unders under one schema (not under one database)