Re: PQoidValue - isn't it for...?

From: Jasen Betts <jasen(at)xnet(dot)co(dot)nz>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: PQoidValue - isn't it for...?
Date: 2009-08-14 10:26:03
Message-ID: h63e3r$1ko$2@reversiblemaps.ath.cx
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 2009-08-12, Jim Michaels <jmichae3(at)yahoo(dot)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 the last 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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alex Paulo 2009-08-14 12:25:18 Table as parameter
Previous Message Jasen Betts 2009-08-14 09:55:26 Re: Does derby have an embedded Mode like Derby ?