Re: PQoidValue - isn't it for...? - Mailing list pgsql-general

From Jasen Betts
Subject Re: PQoidValue - isn't it for...?
Date
Msg-id h63e3r$1ko$2@reversiblemaps.ath.cx
Whole thread Raw
In response to PQoidValue - isn't it for...?  (Jim Michaels <jmichae3@yahoo.com>)
List pgsql-general
On 2009-08-12, Jim Michaels <jmichae3@yahoo.com> wrote:
> --0-1559521671-1250064688=:25681
> Content-Type: text/plain; charset=us-ascii
>
> I am struggling to learn libpq.
>
> for some reason, I could not get an INSERT to produce an Oid.  actually, what I am looking for, is to get the ID of
thelast record inserted or to verify that I inserted a record successfully.  I think you use PQresultStatus() for
that.(?)
>
> Isn't PQoidValue() for getting the last INSERT id?  or am I misunderstanding it?

since 8.0 (iirc) you must specify "WITH OIDS" when you create the
table or you won't get them, you can instead use "RETURNING
someprimarykey" at the end of the insert query (for apropriate
values of someprimarykey) and get a different sort of handle
on the new row

>     Oid oid =  PQoidValue(pgr);
>     if (0 == oid) {
>          printf("ERROR: INSERT operation failed!\n");

You should be printing the result from PQlastError() here too.

pgsql-general by date:

Previous
From: Jasen Betts
Date:
Subject: Re: Does derby have an embedded Mode like Derby ?
Next
From: Alex Paulo
Date:
Subject: Table as parameter