Skip site navigation (1) Skip section navigation (2)

Re: getting primary key values for inserted records?

From: "scott(dot)marlowe" <scott(dot)marlowe(at)ihs(dot)com>
To: Jeremy Buchmann <jeremy(at)wellsgaming(dot)com>
Cc: Andrew Nelson <Andrew(dot)Nelson(at)hsc(dot)utah(dot)edu>,pgsql-jdbc <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: getting primary key values for inserted records?
Date: 2004-01-28 15:55:09
Message-ID: (view raw, whole thread or download thread mbox)
Lists: 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.

In response to

pgsql-jdbc by date

Next:From: michel.verplanckeDate: 2004-01-28 17:40:57
Subject: Connection problem
Previous:From: Dennis Romero L.Date: 2004-01-28 13:58:44
Subject: Re: connectivity problem

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group