Re: Value of sequence last inserted

From: Joe Conway <mail(at)joeconway(dot)com>
To: bryan(at)flyingiranch(dot)com
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Value of sequence last inserted
Date: 2003-03-10 16:46:25
Message-ID: 3E6CC161.1010403@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

bryan(at)flyingiranch(dot)com wrote:
> I have a sequence that I am using on a field that I am using for the ID
> of an item in a table. After an insert to that table, I need to insert
> into two other tables using the same ID - does the initial insert
> somehow return the value of the sequence that was used? I know it may
> not be reliable to do, say "SELECT MAX ID FROM"..., so how can I assure
> that I have the right ID for my other inserts? Should I just do the set
> of inserts as a transaction?
>

See:
http://www.us.postgresql.org/users-lounge/docs/7.3/postgres/functions-sequence.html

specifically look at currval().

HTH,

Joe

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Niclas Hedell 2003-03-10 16:49:41 get the oid
Previous Message Steve Crawford 2003-03-10 16:16:21 Re: [NOVICE] General Performance questions