Thread: prepared statements

prepared statements

From
Vad N
Date:
<br />Hi. <br /><br />How can i pass a set of values to prepared statement?<br /><br />example<br />I have a prepared
query:<br/> select * from users in ( $1 )<br /><br />i would like to pass: 1,2,3,4 and get:<br /><br /> select * from
usersin ( 1,2,3,4 )<br /><br />Any ideas?<br /> 

Re: prepared statements

From
Pavel Stehule
Date:
Hello

2011/12/8 Vad N <vadimid@gmail.com>:
>
> Hi.
>
> How can i pass a set of values to prepared statement?
>
> example
> I have a prepared query:
> select * from users in ( $1 )
>
> i would like to pass: 1,2,3,4 and get:
>
> select * from users in ( 1,2,3,4 )
>
> Any ideas?

use a array parameter, please

regards

Pavel Stehule


Re: prepared statements

From
"David Johnston"
Date:
-----Original Message-----
From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org] On Behalf Of Pavel Stehule
Sent: Thursday, December 08, 2011 2:40 AM
To: Vad N
Cc: pgsql-sql@postgresql.org
Subject: Re: [SQL] prepared statements

Hello

2011/12/8 Vad N <vadimid@gmail.com>:
>
> Hi.
>
> How can i pass a set of values to prepared statement?
>
> example
> I have a prepared query:
> select * from users in ( $1 )
>
> i would like to pass: 1,2,3,4 and get:
>
> select * from users in ( 1,2,3,4 )
>
> Any ideas?

use a array parameter, please

regards

Pavel Stehule

------------------------------------------------------------------

Or, in lieu of readily passing arrays from your client API you can always pass a string and modify the query to parse
thestring into an array. 

... users = ANY ( regexp_split_to_array( $1, ',' )::integer[] )

David J.