From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Stefan Berglund <sorry(dot)no(dot)koolaid(at)for(dot)me> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Is This A Set Based Solution? |
Date: | 2007-03-18 16:47:09 |
Message-ID: | 5686.1174236429@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Stefan Berglund <sorry(dot)no(dot)koolaid(at)for(dot)me> writes:
> I tried this:
> create or replace function foo(plist TEXT)
> RETURNS SETOF Show_Entries as $$
> SELECT *
> FROM Show_Entries
> WHERE Show_ID = 1250 AND Show_Number IN ($1);
> $$ LANGUAGE sql;
> When I use select * from foo('101,110,115,120'); I get no results. When
> I use select * from foo(101,110,115,120); I get the correct results.
Just for the record, the reason that didn't work is that Postgres saw it
as a comparison to a single scalar IN-list item. What you had was
effectively
WHERE Show_ID = 1250 AND Show_Number::text IN ('101,110,115,120');
which of course will fail to find any rows.
In recent releases (8.2 for sure, don't remember if 8.1 can do this
efficiently) you could instead do
create or replace function foo(plist int[])
RETURNS SETOF Show_Entries as $$
SELECT *
FROM Show_Entries
WHERE Show_ID = 1250 AND Show_Number IN ($1);
$$ LANGUAGE sql;
select * from foo(array[101,110,115,120]);
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Martijn van Oosterhout | 2007-03-18 16:54:29 | Re: PostgreSQL 8.2.3 VACUUM Timings/Performance |
Previous Message | Jeff Ross | 2007-03-18 16:44:38 | Shell script to determine if PostgreSQL is accepting connections? |