Search Postgresql Archives

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2009-08-12, Jim Michaels <jmichae3@xxxxxxxxx> 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.

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux