Re: getting primary key values for inserted records? - Mailing list pgsql-jdbc

From scott.marlowe
Subject Re: getting primary key values for inserted records?
Date
Msg-id Pine.LNX.4.33.0401280854210.24964-100000@css120.ihs.com
Whole thread Raw
In response to Re: getting primary key values for inserted records?  (Jeremy Buchmann <jeremy@wellsgaming.com>)
List pgsql-jdbc
On Tue, 27 Jan 2004, Jeremy Buchmann wrote:

> On Jan 27, 2004, at 11:35 AM, Andrew Nelson wrote:
>
> > I've always wondered if something like this is totally safe.  What if
> > someone somewhere else outside of my code ran a insert or update that
> > didn't use the sequence at all but changed the id.  And that id turned
> > out to be the same as the id collect from the select
> > nextval('sequence');
> >
> > So I guess you would need to add a lock of some sorts.
> > Just wondering because this is something I have fought with for a long
> > time.
>
> Well, it's only safe if you use the sequence.  If you don't, you're on
> your own.
>
> Cheers,
> Jeremy

You could always program a before trigger that would not let you directly
insert or update that column, and would only use the sequence.


pgsql-jdbc by date:

Previous
From: Guido Fiala
Date:
Subject: setQueryTimeOut(1) - not expected result...
Next
From: Dave Cramer
Date:
Subject: Re: a little disillusioned now tomcat 5