Re: Return serial from insert

From: Rod Kreisler <rod(at)23net(dot)net>
To: Rory Campbell-Lange <mail(at)campbell-lange(dot)net>, pgsql-novice(at)postgresql(dot)org
Subject: Re: Return serial from insert
Date: 2002-11-08 15:49:46
Message-ID: JNEGKNDJGBKLBDGPOPFOKEDPDEAA.rod@23net.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

You should get the nextval() from the sequence and use that for the new
insert and all related inserts.

> -----Original Message-----
> From: pgsql-novice-owner(at)postgresql(dot)org
> [mailto:pgsql-novice-owner(at)postgresql(dot)org]On Behalf Of Rory
> Campbell-Lange
> Sent: Friday, November 08, 2002 10:30 AM
> To: pgsql-novice(at)postgresql(dot)org
> Subject: [NOVICE] Return serial from insert
>
>
> I would like to return the autoincremented serial number resulting from
> a new insert into a table, ideally as a result from the insert
> statement.
>
> Presumably this is the way to avoid race conditions between inserts into
> the database, because if I do 1) insert then 2) get max sequence val, 2
> might be wrong.
>
> Thanks
> Rory
>
> --
> Rory Campbell-Lange
> <rory(at)campbell-lange(dot)net>
> <www.campbell-lange.net>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org
>
>

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Rory Campbell-Lange 2002-11-08 16:02:07 Re: Return serial from insert
Previous Message Rory Campbell-Lange 2002-11-08 15:29:36 Return serial from insert