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: 87abvect7h.fsf@oxford.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
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
EnterpriseDB http://www.enterprisedb.com

In response to

Browse pgsql-jdbc by date

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