Skip to content

Removed name parameter from Connection::lastInsertId(string $name) problematic for PostgreSQL #7016

@lemon-juice

Description

@lemon-juice

Bug Report

Q A
Version 4.*
Previous Version if the bug is a regression 3.*

Summary

In versions 3 and earlier method Connection::lastInsertId() accepted an optional sequence name. Version 3 made this deprecated and later it was removed. The rationale is described in #4687.

Current behaviour

However, there are scenarios when the sequence name is necessary, at least in PostgreSQL:

  1. There is an insert trigger on table A, and the trigger inserts a new row into table B.
  2. Both table A and B have an identity column.
  3. I insert a new row into table A with Connection::insert() method or with pure SQL.
  4. Connection::lastInsertId() returns value of identity column from table B (because of the trigger) but I want the value from table A and there's no way to do it with this method any longer. I need to use workarounds like manually construct an INSERT ... RETURNING id query or run a query like SELECT currval('table_id_seq').

Expected behaviour

I should be able to specify the name of the sequence like in the old versions for cases with triggers like described above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions