PQoidValue - isn't it for...?

From: Jim Michaels <jmichae3(at)yahoo(dot)com>
To: pgsql general <pgsql-general(at)postgresql(dot)org>
Subject: PQoidValue - isn't it for...?
Date: 2009-08-12 08:11:28
Message-ID: 997203.25681.qm@web34306.mail.mud.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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?

I just figured out how to set the start id of a BIGSERIAL to 1000.

SAMPLE OUTPUT:

firstname:Horatio
middlename:P
lastname:Algers
homephone:345-678-9012
workphone:
cellphone:
pager:
company:
address1:
address2:
city:
mailstop:
stateprovince:
postalcode:
country:
comment:abc,123,456
website:
emailhome:
emailwork:
QUERY:"INSERT INTO s_phonelist.phonelist(firstname,middlename,lastname,homephone,workphone,cellphone,pager,company,address1,address2,city,mailstop,stateprovi
,postalcode,country,_comment,website,emailhome,emailwork)
VALUES('Horatio','P','Algers','345-678-9012','','','','','','','','','','','','abc,123,456','','','')"
ERROR: INSERT operation failed!
done.

sprintf(querystr, "INSERT INTO s_phonelist.phonelist(%s)\n"
"VALUES(%s)", fnl, vl);
printf("QUERY:\"%s\"\n", querystr);
pgr = PQexec(pgc,querystr);

if (PGRES_COMMAND_OK!=PQresultStatus(pgr)) {
printf("INSERT result is not OK\n");
} else {
Oid oid = PQoidValue(pgr);
if (0 == oid) {
printf("ERROR: INSERT operation failed!\n");
}
}

Jim Michaels <jmichae3(at)yahoo(dot)com>

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tommy Gildseth 2009-08-12 08:12:02 Re: Best way to "mask" password in DBLINK
Previous Message Ow Mun Heng 2009-08-12 08:10:59 Re: Best way to "mask" password in DBLINK