From: Bruno Wolff III <bruno@wolff.to>
To: josh@segrestfarms.com <josh@segrestfarms.com>
Cc: pgsql-admin@postgresql.org
Subject: Re: SQL Help - Obtaining ID of record INSERTED
Date: Tue, 16 Aug 2005 23:40:06 -0500
Message-ID: <20050817044006.GA32756@wolff.to> (raw)
In-Reply-To: <430255F0.7060500@segrestfarms.com>
References: <430255F0.7060500@segrestfarms.com>
On Tue, Aug 16, 2005 at 17:09:04 -0400,
"josh@segrestfarms.com" <josh@segrestfarms.com> wrote:
> Greetings.
>
> INSERT INTO
> orderstemp (customerid,datecreated)
> VALUES
> ('5443','8/16/2005 12:00PM')
>
> The table orderstemp has a unique identifier field, orderid (of type
> SERIAL).
>
> How can I obtain the orderid of the record inserted in the INSERT INTO
> statement in postgresql?
>
> MSSQL does it like this:
>
> INSERT INTO
> orderstemp (customerid,datecreated)
> VALUES
> ('5443','8/16/2005 12:00PM')
> SELECT @@identity as orderid
>
> but this doens't work in postgresql.
>
> Any ideas? Thanks in advance.
You want to use currval. In 8.0 you would use:
SELECT currval(pg_get_serial_sequence('orderstemp', 'orderid'));
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: bruno@wolff.to, josh@segrestfarms.com
Subject: Re: SQL Help - Obtaining ID of record INSERTED
In-Reply-To: <20050817044006.GA32756@wolff.to>
References: <430255F0.7060500@segrestfarms.com> <20050817044006.GA32756@wolff.to>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox