Re: Last inserted id

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Dhorwitz(at)ched(dot)uct(dot)ac(dot)za
Cc: "'pgsql-odbc(at)postgresql(dot)org'" <pgsql-odbc(at)postgresql(dot)org>
Subject: Re: Last inserted id
Date: 2001-11-12 15:29:52
Message-ID: 14006.1005578992@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-odbc

David Horwitz <Dhorwitz(at)ched(dot)uct(dot)ac(dot)za> writes:
> Actually the issue is b) is multi-user safe
> *if* you have an exclusive lock on the table. If you don't it is quite
> possible for a user to insert an other record between your insertion and the
> currval() call

False. Option B is multi-user safe, period. The reason is that currval
returns the value last obtained by nextval *in your own session*,
independently of what anyone else has done meanwhile.

I tend to prefer option A (select nextval and insert) myself, just
because it seems more intuitive. But if that's not convenient for
some reason, option B works fine too.

regards, tom lane

In response to

Responses

Browse pgsql-odbc by date

  From Date Subject
Next Message Dave Page 2001-11-12 15:50:29 Re: Last inserted id
Previous Message Simeó Reig 2001-11-12 14:27:39 Re: Last inserted id