Re: Array paramiters - Mailing list pgsql-jdbc

From Gregory Stark
Subject Re: Array paramiters
Date
Msg-id 87abvect7h.fsf@oxford.xeocode.com
Whole thread Raw
In response to Re: Array paramiters  ("ben sagal" <bsagal@gmail.com>)
List pgsql-jdbc
"ben sagal" <bsagal@gmail.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
  EnterpriseDB          http://www.enterprisedb.com


pgsql-jdbc by date:

Previous
From: Pete Lewin-Harris
Date:
Subject: Re: Array paramiters
Next
From: mljv@planwerk6.de
Date:
Subject: bug with prepared statements and sql comments in 8.1-408.jdbc3