Re: [SQL] Retrieving the new "nextval" for primary keys....

From: GB Clark <postgres(at)vsservices(dot)com>
To: friedrich nietzsche <nietzsche_psql(at)yahoo(dot)it>
Cc: pgsql-sql(at)postgresql(dot)org, pgsql-general(at)postgresql(dot)org
Subject: Re: [SQL] Retrieving the new "nextval" for primary keys....
Date: 2002-09-02 19:50:33
Message-ID: 20020902145033.4a621385.postgres@vsservices.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql

On Wed, 28 Aug 2002 18:36:10 +0200 (CEST)
friedrich nietzsche <nietzsche_psql(at)yahoo(dot)it> wrote:

> One solution seems to locking table(s),
> but I prefer to leave it as last chance...
> using table locks, and the trick of writing and
> suddenly reading back from DB it probably works,
> but it doesn't seems so sexy... :)
> ciao
> danilo
>

Why would you have to lock the table? currval() is connection safe.

I would either do the insert and then do a currval() OR do a nextval()
and do the insert. Either one would work. I always just do the insert
and then call currval() to get the current serial number for the connection.

GB

--
GB Clark II | Roaming FreeBSD Admin
gclarkii(at)VSServices(dot)COM | General Geek
CTHULU for President - Why choose the lesser of two evils?

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Randall Perry 2002-09-02 20:47:10 Re: [GENERAL] Access 'field too long' error
Previous Message Tom Lane 2002-09-02 16:24:00 Re: [GENERAL] Access 'field too long' error

Browse pgsql-sql by date

  From Date Subject
Next Message GB Clark 2002-09-02 19:57:26 Re: Retrieving the new nextval...
Previous Message Jean-Luc Lachance 2002-08-30 20:02:53 Re: query problem