dbdpg icon indicating copy to clipboard operation
dbdpg copied to clipboard

Add support for $sth->last_insert_id()

Open pali opened this issue 6 years ago • 2 comments

DBI API since version 1.642 has support for last_insert_id also for statement handle (not only database handle), see: https://metacpan.org/pod/DBI#last_insert_id1

It would be nice if DBD::Pg supports and implement this method.

Difference between $dbh->last_insert_id and $sth->last_insert_id is that $dbh's one returns last global insert id and $sth's one returns insert id for the last executed query by $sth.

pali avatar Sep 27 '19 08:09 pali

Given the way that DBD::Pg interacts between $sth and $dbh, I don't see a way to make $sth->last_insert_id different from $dbh->last_insert_id. But maybe that's ok. I added some tests for $sth->last_insert_id in 2b11c6d273375f1996b66600c439937b6f57d313

If you can think of a way to differentiate the two, please update this issue.

turnstep avatar Jun 23 '20 16:06 turnstep

Is it feasible to call $dbh->last_insert_id after every query and store its value in the $sth?

dboehmer avatar Sep 24 '22 08:09 dboehmer