Re: return column id from insert

From: Oliver Elphick <olly(at)lfix(dot)co(dot)uk>
To: Rory Campbell-Lange <mail(at)campbell-lange(dot)net>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: return column id from insert
Date: 2002-11-12 14:27:08
Message-ID: 1037111228.11992.817.camel@linda
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Tue, 2002-11-12 at 11:50, Rory Campbell-Lange wrote:
> I asked a question about this earlier, and didn't get a response I
> understood!
>
> The issue is this:
> I need to make a database insert and then make an image with the
> resulting column id number, which is provided by a sequence.
>
> This has to be a single action, otherwise I could fall into a race
> condition with another insert going on concurrently.

Use the function currval('sequence_name') to get the last value
generated by that sequence in your current session. You must have
previously called nextval('sequence_name') in the same session, either
explicitly or through an insert to a table with a SERIAL type field.

--
Oliver Elphick Oliver(dot)Elphick(at)lfix(dot)co(dot)uk
Isle of Wight, UK
http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C
========================================
"He that loveth father of mother more than me is not
worthy of me; and he that loveth son or daughter more
than me is not worthy of me. And he that taketh not
his cross, and followeth after me, is not worthy of
me." Matthew 10:37,38

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Patrick Hatcher 2002-11-12 16:16:12 Re: Cancelling long running query?
Previous Message Tom Lane 2002-11-12 13:26:47 Re: oidin error when parsing XML documents