At 23:50 26/11/2007, you wrote:
Date: Mon, 26 Nov 2007 18:19:07 -0600

I need to access the last inserted record in a postgresql database table
from php. I connect to the db using pg_connect
I construct the query string, and I use pg_query to send the query. I get
the record inserted, of course. One of the fields,
which is my primary key,  is an autoincrement field. I need to fetch this
value. Any idea? I would really apreciate your helping me.

SELECT primary_key_name FROM database_table ORDER BY primary_key_name DESC

Just use whatever cursor or LIMIT you can in Postgres to get a single record.
If it's autoincrement, then the last record ordered in descending order is, the last record ;-)

Cheers - Neil
PHP Database Mailing List (
To unsubscribe, visit:

Reply via email to