php3-list | 200003

RE: [PHP3] PostgreSQL Object ID from INSERT From: Peter Mount (petermount <email protected>)
Date: 03/10/00

If you know the sequence, you can use:

select currval('sequencename');

ie, if the field name is id and the table mytable, the sequence name
will be mytable_id_seq

PS: This is safe as currval uses the cached value in the backend for
that session, so if another backend session increments the sequence,
currval will return the correct value, not the latest one.

Peter

-- 
Peter Mount
Enterprise Support
Maidstone Borough Council
Any views stated are my own, and not those of Maidstone Borough Council.

-----Original Message----- From: Andrew Hill [mailto:list <email protected>] Sent: Friday, March 10, 2000 5:10 AM To: PHP List Subject: [PHP3] PostgreSQL Object ID from INSERT

Hi,

I've set up a table in PostgreSQL using a serial SEQUENCE as a primary key.

Using PHP, I insert information into the database by using:

$result = pg_exec ($database, "INSERT INTO.... ;");

where $database is the database in question, and all information except the field for the serial SEQUENCE is inserted.

What I need to do now is to be able to now do a SELECT on that new entry, so I can get the number that PostgreSQL has assigned for the SEQUENCE.

I know I can use:

$oid = pg_getlastoid ($result);

to get the Object ID of the last INSERT that was done, but I am not clear on how I can use $oid to now select the SEQUENCE field from that recently inserted row.

Ideas?

TIA, --

Andrew Hill

-- PHP 3 Mailing List <http://www.php.net/> To unsubscribe, send an empty message to php3-unsubscribe <email protected> To subscribe to the digest, e-mail: php3-digest-subscribe <email protected> To search the mailing list archive, go to: http://www.php.net/mailsearch.php3 To contact the list administrators, e-mail: php-list-admin <email protected>

-- PHP 3 Mailing List <http://www.php.net/> To unsubscribe, send an empty message to php3-unsubscribe <email protected> To subscribe to the digest, e-mail: php3-digest-subscribe <email protected> To search the mailing list archive, go to: http://www.php.net/mailsearch.php3 To contact the list administrators, e-mail: php-list-admin <email protected>