Re: SQL Help - Obtaining ID of record INSERTED

From: Juan Miguel Paredes <juan(dot)paredes(at)gmail(dot)com>
To: pgsql-admin(at)postgresql(dot)org
Cc: josh(at)segrestfarms(dot)com
Subject: Re: SQL Help - Obtaining ID of record INSERTED
Date: 2005-08-16 21:35:25
Message-ID: 9e0a2869050816143527ebc2f4@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Greetings, all!

As described in
http://www.postgresql.org/docs/8.0/interactive/datatype.html#DATATYPE-SERIAL,
column "type" SERIAL is really an integer type with an implicit
sequence associated by default with that column. In order to get the
last generated value from the sequence, use the "currval" function, as
described in http://www.postgresql.org/docs/8.0/interactive/functions-sequence.html.

Hope this helps!

On 8/16/05, josh(at)segrestfarms(dot)com <josh(at)segrestfarms(dot)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.
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
>

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Jason Minion 2005-08-16 21:42:39 Re: SQL Help - Obtaining ID of record INSERTED
Previous Message josh@segrestfarms.com 2005-08-16 21:09:04 SQL Help - Obtaining ID of record INSERTED