mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Using lastval() instead of currval('sequence_name') for fetching IDs can return wrong ID #7489
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Brajk19 on GitHub (Mar 21, 2025).
In ORM 2, newly inserted IDs in Postgres were fetched using:
However, in Doctrine ORM 3, this has been changed to:
This change introduces an issue when using tools like pg_repack (or triggers in general), which create triggers that make insert into log table while doing table repack. These inserts cause another sequence to increment, meaning that
lastval()may return an ID from the wrong sequence.I understand that this change was made because of issues with Oracle (https://github.com/doctrine/dbal/issues/4687) but i I think it would be useful if this behaviour could be modified.
For Postgres it makes more sense to use
currval('sequence_name').Even having option to define our own generator when using
#[ORM\GeneratedValue(strategy: 'IDENTITY')]would be useful.Currently it depends on type so only
IdentityGeneratorandBigIntegerIdentityGeneratorcan be used:1072ea6db4/src/Mapping/ClassMetadataFactory.php (L556-L558)