Re: Get the last inserted id - Mailing list pgsql-sql

From Nacef LABIDI
Subject Re: Get the last inserted id
Date
Msg-id f16f7ea00804111043t67ddf4b8gc18a9780ecaa47eb@mail.gmail.com
Whole thread Raw
In response to Re: Get the last inserted id  ("Scott Marlowe" <scott.marlowe@gmail.com>)
List pgsql-sql
Nice idea but how can I use this in a frontend that I am developing using Delphi and ADO objects ?

On Fri, Apr 11, 2008 at 7:41 PM, Scott Marlowe <scott.marlowe@gmail.com> wrote:
On Fri, Apr 11, 2008 at 11:23 AM, Nacef LABIDI <nacef.l@gmail.com> wrote:
> Hi all,
>
> I was wondering if postgres can return the last ID inserted for a table
> which the primary key is autoincremented. I need to retrieve this ID in my
> code to continue processing on that inserted row.

smarlowe=# create table test (a serial primary key, b text);
NOTICE:  CREATE TABLE will create implicit sequence "test_a_seq" for
serial column "test.a"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index
"test_pkey" for table "test"
CREATE TABLE
smarlowe=# insert into test (a,b) values (DEFAULT,'test') returning a;
 a
---
 1
(1 row)

INSERT 0 1

Note that there are other ways of doing it, but I really like the
returning clause.

pgsql-sql by date:

Previous
From: "Scott Marlowe"
Date:
Subject: Re: Get the last inserted id
Next
From: "A. Kretschmer"
Date:
Subject: Re: Get the last inserted id