Skip site navigation (1) Skip section navigation (2)

Re: Array paramiters

From: Gregory Stark <stark(at)enterprisedb(dot)com>
To: "ben sagal" <bsagal(at)gmail(dot)com>
Cc: "Andreas Joseph Krogh" <andreak(at)officenet(dot)no>, <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: Array paramiters
Date: 2007-06-05 15:32:50
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-jdbc
"ben sagal" <bsagal(at)gmail(dot)com> writes:

> I would ideally like to use a prepared statement, in which i can on each
> execution insert a different array? the method u suggest will not allow use
> of a prepared statement.

The alternative is building up a string form of an array of your list of
parameters and passing it as a single parameter.

Something like

$sth = $dbh->prepare("select * from foo where bar =ANY(?::int[])")
$sth->execute('{' . join(@array, ',') . '}');

This works better with something like integers for which you don't have to
worry about escaping. The method the other poster suggested would be lower
overhead I think but this only gives you one prepared query if you have a wide
variety of lengths of lists.

  Gregory Stark

In response to

pgsql-jdbc by date

Next:From: Kris JurkaDate: 2007-06-05 18:07:40
Subject: Re: bug with prepared statements and sql comments in 8.1-408.jdbc3
Previous:From: Andreas Joseph KroghDate: 2007-06-05 15:22:50
Subject: Re: Connection Pool

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group