Thread: PREPARE query with IN?

PREPARE query with IN?

From
Ivan Voras
Date:
Is it possible to prepare a query with the IN clause in a meaningful
way? I could probably do it with a hard-coded number of arguments, like
"SELECT x FROM t WHERE y IN ($1, $2, $3)" but that kind of misses the
point of using IN for my needs.

In any case, it would probably be a good idea to add a sentence about it
on http://www.postgresql.org/docs/8.3/interactive/sql-prepare.html since
I'm probably not the first one to ask about it :)

Re: PREPARE query with IN?

From
Filip Rembiałkowski
Date:
filip@filip=# prepare sth(int[]) as select * from ids where id = ANY($1);
PREPARE

filip@filip=# execute sth('{1,2,3}');
 id |   t
----+-------
  1 | eenie
  2 | menie
  3 | moe
(3 rows)



2009/8/6 Ivan Voras <ivoras@freebsd.org>
Is it possible to prepare a query with the IN clause in a meaningful
way? I could probably do it with a hard-coded number of arguments, like
"SELECT x FROM t WHERE y IN ($1, $2, $3)" but that kind of misses the
point of using IN for my needs.

In any case, it would probably be a good idea to add a sentence about it
on http://www.postgresql.org/docs/8.3/interactive/sql-prepare.html since
I'm probably not the first one to ask about it :)


--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



--
Filip Rembiałkowski
JID,mailto:filip.rembialkowski@gmail.com
http://filip.rembialkowski.net/

Re: PREPARE query with IN?

From
Ivan Voras
Date:
Filip Rembiałkowski wrote:
> filip@filip=# prepare sth(int[]) as select * from ids where id = ANY($1);
> PREPARE
>
> filip@filip=# execute sth('{1,2,3}');
>  id |   t
> ----+-------
>   1 | eenie
>   2 | menie
>   3 | moe
> (3 rows)

Thanks!

> 2009/8/6 Ivan Voras <ivoras@freebsd.org <mailto:ivoras@freebsd.org>>
>
>     Is it possible to prepare a query with the IN clause in a meaningful
>     way? I could probably do it with a hard-coded number of arguments, like
>     "SELECT x FROM t WHERE y IN ($1, $2, $3)" but that kind of misses the
>     point of using IN for my needs.
>
>     In any case, it would probably be a good idea to add a sentence about it
>     on http://www.postgresql.org/docs/8.3/interactive/sql-prepare.html since
>     I'm probably not the first one to ask about it :)
>
>
>     --
>     Sent via pgsql-general mailing list (pgsql-general@postgresql.org
>     <mailto:pgsql-general@postgresql.org>)
>     To make changes to your subscription:
>     http://www.postgresql.org/mailpref/pgsql-general
>
>
>
>
> --
> Filip Rembiałkowski
> JID,mailto:filip.rembialkowski@gmail.com
> <mailto:filip.rembialkowski@gmail.com>
> http://filip.rembialkowski.net/