Re: libpq - getting value of SERIAL field when INSERT-ing? - Mailing list pgsql-novice

From Tom Lane
Subject Re: libpq - getting value of SERIAL field when INSERT-ing?
Date
Msg-id 620.1314749568@sss.pgh.pa.us
Whole thread Raw
In response to libpq - getting value of SERIAL field when INSERT-ing?  (Roy's Email <rmw256@hotmail.com>)
List pgsql-novice
"Roy's Email" <rmw256@hotmail.com> writes:
> Using libpq, how do I get the return value from an INSERT statement?

> CREATE TABLE foo ( pk SERIAL , val text, PRIMARY KEY (pk) );
> INSERT INTO foo VALUES ( DEFAULT, 'stuff' ) RETURNING (pk);

> How do I get the value assigned to 'pk'?  I assume it's in the 'PGresult' returned from 'PQexec()', but I can't find
anythingin the documentation for 'PGresult' that appears to discuss this particular use. 

The PGresult is exactly the same as if you'd done "SELECT pk FROM ..."

            regards, tom lane

pgsql-novice by date:

Previous
From: Roy's Email
Date:
Subject: libpq - getting value of SERIAL field when INSERT-ing?
Next
From: 金 今花
Date:
Subject: pg_dump error