pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tobias Thierer <t_thierer@yahoo.de>
To: pgsql-jdbc@postgresql.org
Subject: Re: escape string for pgsql (using jdbc/java)?
Date: Tue, 30 Jan 2007 13:15:08 +1300
Message-ID: <epm2ma$2jnm$1@news.hub.org> (raw)
In-Reply-To: <2473B100-9BC0-42F1-9CE5-02DF41E49569@fastcrypt.com>
References: <epbeqa$1g90$1@news.hub.org>
	<Pine.BSO.4.64.0701251936550.15719@leary2.csoft.net>
	<epgu2j$2jrk$1@news.hub.org>
	<45BD294D.5040002@opencloud.com>
	<eplvti$2deb$1@news.hub.org>
	<2473B100-9BC0-42F1-9CE5-02DF41E49569@fastcrypt.com>

Hi,

Dave Cramer wrote:

>> I'm not so worried about the performance. But if I have a column of 
>> type SERIAL in my table, then I can retrieve the generated value using:
[...]

> You could if that worked in postgresql but getGeneratedKeys does not 
> currently work

Yes, I was actually just about to post a follow-up to my previous message 
because I just found out that pgsql doesn't support this.

>> whereas it is not clear to me how this works with a prepared 
>> statement. Strangely, PreparedStatement extends Statement, so 
>> PreparedStatement still has the executeUpdate(String,int) method - but 
>> it is not clear to me whether this method will throw the previously 
>> prepared statement away or what.
>>
>> Is there any easy way to retrieve the generated value for the SERIAL 
>> column when using a prepared statement?
>>
> Yes, if it worked it would work with prepared statements.

Yes, I just found that out too.

But given that pgsql doesn't allow me to immediately retrieve the value of 
the autogenerated key, how can I (or can't I!?)? If I made a

    SELECT MAX(id)

statement right afterwards then I couldn't be sure that that is the id just 
generated, because due to concurrency someone else may have just submitted 
an entry too, right?

How are these things done in pgsql?

   Tobias



view thread (10+ messages)  latest in thread

Message-ID: <epm2ma$2jnm$1@news.hub.org>
Permalink:  ../epm2ma$2jnm$1@news.hub.org/
Also on:    postgresql.org/message-id/epm2ma$2jnm$1@news.hub.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: t_thierer@yahoo.de
  Subject: Re: escape string for pgsql (using jdbc/java)?
  In-Reply-To: <epm2ma$2jnm$1@news.hub.org>
  References: <epbeqa$1g90$1@news.hub.org> <Pine.BSO.4.64.0701251936550.15719@leary2.csoft.net> <epgu2j$2jrk$1@news.hub.org> <45BD294D.5040002@opencloud.com> <eplvti$2deb$1@news.hub.org> <2473B100-9BC0-42F1-9CE5-02DF41E49569@fastcrypt.com> <epm2ma$2jnm$1@news.hub.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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