From: | Bruno Wolff III <bruno(at)wolff(dot)to> |
---|---|
To: | "josh(at)segrestfarms(dot)com" <josh(at)segrestfarms(dot)com> |
Cc: | pgsql-admin(at)postgresql(dot)org |
Subject: | Re: SQL Help - Obtaining ID of record INSERTED |
Date: | 2005-08-17 04:40:06 |
Message-ID: | 20050817044006.GA32756@wolff.to |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-admin |
On Tue, Aug 16, 2005 at 17:09:04 -0400,
"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.
You want to use currval. In 8.0 you would use:
SELECT currval(pg_get_serial_sequence('orderstemp', 'orderid'));
From | Date | Subject | |
---|---|---|---|
Next Message | sandhya | 2005-08-17 08:09:23 | error numbers in postgresql |
Previous Message | Tom Lane | 2005-08-17 03:02:46 | Re: Is there anyway to create a functional index using to_date? |