Re: Retrieving tuple data on insert

From: "Prasanth" <lqdcore(at)bellsouth(dot)net>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Retrieving tuple data on insert
Date: 2003-08-08 21:01:30
Message-ID: 84UYa.3431$vK4.1253@fe05.atl2.webusenet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

you can retrieve it using the currentVal function on the
sequence used to generate that id.

"sebmil" <sebmil(at)invalid(dot)mail> wrote in message
news:pan(dot)2003(dot)07(dot)24(dot)03(dot)59(dot)01(dot)164717(at)invalid(dot)mail(dot)(dot)(dot)
> Hello,
>
> I have a table with two columns, created with : CREATE TABLE test ( id
> serial primary key, name text ) ;
>
> To populate the table i use :
> INSERT INTO test(name) values('test1'); so the "id" is automatically set
> by PostgreSQL.
>
> Now the problem, i would like to retrieve the value of "id" that
> PostgreSQL assigns to this tuple, but i can't make a SELECT on the name i
> just inserted because it's not UNIQUE, so SELECT may return multiple
> results.
>
> Is there a way to retrieve the value of "id" from the insertion ?
>
> I was thinking of something with Oids, like getting the Oid of the INSERT
> statement then use it to SELECT the tuple, but i didn't find what to do
> with an Oid in PostgreSQL documentation.
>
> Also, it would be better if it was possible in only one operation (not
> INSERT then SELECT).
>
> Thanks in advance.

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Josh Berkus 2003-08-08 21:45:44 Re: Abort Transaction DP PK (again)
Previous Message alexandre :: aldeia digital 2003-08-08 20:22:26 Re: Abort Transaction DP PK (again)