FW: Libpq and the SQL RETURNING clause

View: New views
2 Messages — Rating Filter:   Alert me  

FW: Libpq and the SQL RETURNING clause

by Georges.Brefort :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

 


From: Brefort, Georges R&D/FR
Sent: Tuesday, August 26, 2008 2:41 PM
To: pgsql-interfaces@...
Subject: Libpq and the SQL RETURNING clause

Dear Postgres specialist,
 
1 Assume you have a table such as the following:
 
CREATE TABLE example( id SERIAL, someData VARCHAR(32) );
 
2 Now, you use a SQL statement to insert the data and get the the id value back:
 
INSERT INTO example( someData ) VALUES( 'BlaBlaBla' ) RETURNING id; 
 
I wonder if it is possible to retrieve the value of the id field in an application using the C libpq library.
 
I pretty much understand how to bind data with the libpq, or how to retrieve result sets from a SELECT SQL statement, but not how to retrieve data from that RETURNING clause. (I have many years of practice of the RETURNING clause in the ORACLE C library, but that is not the point here).
 
Thank you very much for your help and your patience.
With my best regards.
 
Georges BREFORT

Re: FW: Libpq and the SQL RETURNING clause

by Keary Suska :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

8/27/08 8:28 AM, also sprach Georges.Brefort@...:

>  
>
> ________________________________
>
> From: Brefort, Georges R&D/FR
> Sent: Tuesday, August 26, 2008 2:41 PM
> To: pgsql-interfaces@...
> Subject: Libpq and the SQL RETURNING clause
>
>
> Dear Postgres specialist,
>  
> 1 Assume you have a table such as the following:
>  
> CREATE TABLE example( id SERIAL, someData VARCHAR(32) );
>  
> 2 Now, you use a SQL statement to insert the data and get the the id
> value back:
>  
> INSERT INTO example( someData ) VALUES( 'BlaBlaBla' ) RETURNING id;
>  
> I wonder if it is possible to retrieve the value of the id field in an
> application using the C libpq library.

Yes. I do it all the time. Simply treat the result as if it was from a
select statement.
 
HTH,

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"



--
Sent via pgsql-interfaces mailing list (pgsql-interfaces@...)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-interfaces