PHP Postgres: Get Last Insert ID PHP Postgres: Get Last Insert ID postgresql postgresql

PHP Postgres: Get Last Insert ID


INSERT, UPDATE and DELETE in PostgreSQL have a RETURNING clause which means you can do:

INSERT INTO ....RETURNING id;

Then the query will return the value it inserted for id for each row inserted. Saves a roundtrip to the server.


Yes, the sequence functions provide multiuser-safe methods for obtaining successive sequence values from sequence objects.