Re: SERIAL behaviour

From: Steve Brett <SBrett(at)e-mis(dot)com>
To: Adrian 'Dagurashibanipal' von Bidder <avbidder(at)fortytwo(dot)ch>, pgsql-general(at)postgresql(dot)org
Subject: Re: SERIAL behaviour
Date: 2002-07-15 13:59:28
Message-ID: C05E7DA1218ED411BF8A00105AC95A8E05B71AEB@sv-cntrmail.emis.local
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

you can use currval() to get the current value of a sequence.

however if your key value is set to serial and it's default is the nextval
then don't reference it in your insert i.e.

insert into foo(forename,surname) values ('Steve','Brett');

where the key for foo is an id of type serial.

currval() 'should' be safe for use within transactions.

Steve

> -----Original Message-----
> From: Adrian 'Dagurashibanipal' von Bidder
> [mailto:avbidder(at)fortytwo(dot)ch]
> Sent: 15 July 2002 14:47
> To: pgsql-general(at)postgresql(dot)org
> Subject: Re: [GENERAL] SERIAL behaviour
>
>
> On Sun, 2002-07-14 at 03:59, Eugene wrote:
> [ SERIAL type / SEQUENCEs and transactions ]
>
> Closely related: what's the official/preferred way if I'm
> inserting rows
> into a table with a auto assigned id (SERIAL), to get the
> newly created
> id? asking the sequence obviously will not work - as the sequence will
> advance when the next value is inserted from another transaction.
>
> cheers
> -- vbi
>
> --
> secure email with gpg http://fortytwo.ch/gpg
>

Browse pgsql-general by date

  From Date Subject
Next Message Martijn van Oosterhout 2002-07-15 14:07:12 Re: SERIAL behaviour
Previous Message Curt Sampson 2002-07-15 13:53:11 Re: recursing down a tree