Re: expression IN value list - Mailing list pgsql-jdbc

From Michael Stephenson
Subject Re: expression IN value list
Date
Msg-id Pine.LNX.4.44.0309080900210.579-100000@tirin.openworld.co.uk
Whole thread Raw
In response to expression IN value list  ("Andy Kriger" <akriger@greaterthanone.com>)
List pgsql-jdbc
Andy wrote:
> Does anyone know how to setup this query using a PreparedStatement?
>
> DELETE FROM table WHERE id IN (list of values)

This has been discussed quite recently on this list, from what I can
remember you basically have two choices:

1. Dynamically generating the prepared statement string with the correct
number of question marks.

2. Add more ?'s than you'll ever need and set all the excess ones to null.

> Would it be significantly faster to do a query like this (where there
> could be hundreds of values) versus running the DELETE separately for
> each value (opening a new db connection each time)?

Yes, if you send a delete for each value you'll get a network round trip
for each delete, against a single round trip for the above version.

This used to be the case even if you batched them, I don't know if this
has changed.

Michael

--
Web Applications Developer
Open World Ltd, 11 Riverside Court, Riverside Road, Bath, BA2 3DZ.
Tel: +44 1225 444950  Fax: +44 1225 336738  http://www.openworld.co.uk/

CONFIDENTIALITY NOTICE
The information contained in this message is confidential, intended only
for the use of the individual or the entity named as recipient. If the
reader of this message is not that recipient, you are notified that any
dissemination, distribution or copy of this message is strictly
prohibited. If you have received this message in error, please immediately
notify us by telephone on the number above. Your co-operation is
appreciated.


pgsql-jdbc by date:

Previous
From: James Robinson
Date:
Subject: Re: JBoss w/int8 primary keys in postgres ...
Next
From: Kris Jurka
Date:
Subject: SQLState implementation for V3 Protocol