From: | Erik Jones <erik(at)myemma(dot)com> |
---|---|
To: | Gustavo Tonini <gustavotonini(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Argument type list |
Date: | 2007-08-23 17:14:43 |
Message-ID: | 4F341451-B1B2-431D-AB5C-0D33D89F404D@myemma.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Aug 23, 2007, at 11:56 AM, Gustavo Tonini wrote:
> I want to create a function that receive a list argument and filter
> data with IN operator. Example:
>
> CREATE OR REPLACE FUNCTION "public"."ffoo" (list ???) RETURNS VOID AS
> $body$
> BEGIN
> select * from foo where foo_column in list;
> END;
> $body$
> LANGUAGE 'plpgsql' ;
>
> I played with arrays but I got no success...
> Is it possible? How proceed?
Without knowing the data type of foo_column we can't really give a
"best" solution, but with an array you could do something like (not
tested):
CREATE OR REPLACE FUNCTION public.ffoo(list sometype[]) RETURNS VOID
AS $$
BEGIN
execute 'select * from foo where foo_column::text in (' ||
array_to_string(list, ',') || ');';
END;
$$
LANGUAGE plpgsql;
Note that if foo_column is already a text type you don't need the cast.
Erik Jones
Software Developer | Emma®
erik(at)myemma(dot)com
800.595.4401 or 615.292.5888
615.292.0777 (fax)
Emma helps organizations everywhere communicate & market in style.
Visit us online at http://www.myemma.com
From | Date | Subject | |
---|---|---|---|
Next Message | Joshua D. Drake | 2007-08-23 17:16:48 | Re: Apache + PHP + Postgres Interaction |
Previous Message | Tom Lane | 2007-08-23 17:08:01 | Re: Undetected corruption of table files |