amphp / postgres

Async Postgres client for PHP based on Amp.
MIT License
96 stars 20 forks source link

[feature request]: last insert oid #49

Closed azjezz closed 2 years ago

azjezz commented 2 years ago

The pg driver offers pg_last_oid function that can be used to retrieve the last oid from a result, however, amphp doesn't offer a high level access to this function ( similar to the getLastInsertId in amphp/mysql ), or access to the underlying result handle.

I think adding getLastInsertId would be a good start, while offering access to the underlying result handle ( or possible all types of handles, e.g: pg handle, socket connection, ... etc ) might be dangerous, it's a good feature to have that would allow people that know what they are doing to play around.

azjezz commented 2 years ago

ref: https://github.com/neutomic/neu/tree/feat/database

trowski commented 2 years ago

OIDs are not the same as MySQL's auto_increment columns: https://stackoverflow.com/questions/5625585/sql-postgres-oids-what-are-they-and-why-are-they-useful

To retrieve the last value of a sequence, use RETURNING on the query: https://www.postgresql.org/docs/14/dml-returning.html