Skip site navigation (1) Skip section navigation (2)

libpq - getting value of SERIAL field when INSERT-ing?

From: Roy's Email <rmw256(at)hotmail(dot)com>
To: <pgsql-novice(at)postgresql(dot)org>
Subject: libpq - getting value of SERIAL field when INSERT-ing?
Date: 2011-08-31 00:08:07
Message-ID: BAY161-W47D80B4AF95A1A565E6B396160@phx.gbl (view raw or flat)
Thread:
Lists: pgsql-novice
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 anything in the documentation for 'PGresult' that appears to discuss this particular use.

Regards, 

- Roy 

=*=*= 
Always do right. 
This will gratify some people and astonish the rest. - Mark Twain 

The truth is rarely pure, and never simple. - Oscar Wilde
 
 		 	   		  

Responses

pgsql-novice by date

Next:From: Tom LaneDate: 2011-08-31 00:12:48
Subject: Re: libpq - getting value of SERIAL field when INSERT-ing?
Previous:From: Merlin MoncureDate: 2011-08-30 22:36:25
Subject: Re: Trouble including "pg_type.h"

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group