pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
prepared statements
3+ messages / 3 participants
[nested] [flat]

* prepared statements
@ 2011-12-07 23:04  Vad N <vadimid@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Vad N @ 2011-12-07 23:04 UTC (permalink / raw)
  To: pgsql-sql

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?

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: prepared statements
@ 2011-12-08 07:40  Pavel Stehule <pavel.stehule@gmail.com>
  parent: Vad N <vadimid@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Pavel Stehule @ 2011-12-08 07:40 UTC (permalink / raw)
  To: Vad N <vadimid@gmail.com>; +Cc: pgsql-sql

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



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: prepared statements
@ 2011-12-08 14:42  David Johnston <polobo@yahoo.com>
  parent: Pavel Stehule <pavel.stehule@gmail.com>
  0 siblings, 0 replies; 3+ messages in thread

From: David Johnston @ 2011-12-08 14:42 UTC (permalink / raw)
  To: 'Pavel Stehule' <pavel.stehule@gmail.com>; 'Vad N' <vadimid@gmail.com>; +Cc: pgsql-sql

-----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 the string into an array.

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

David J.





^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2011-12-08 14:42 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-12-07 23:04 prepared statements Vad N <vadimid@gmail.com>
2011-12-08 07:40 ` Pavel Stehule <pavel.stehule@gmail.com>
2011-12-08 14:42   ` David Johnston <polobo@yahoo.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox