Description
In ORM 2, newly inserted IDs in Postgres were fetched using:
SELECT currval('sequence_name')
However, in Doctrine ORM 3, this has been changed to:
SELECT lastval()
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 (doctrine/dbal#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 IdentityGenerator
and BigIntegerIdentityGenerator
can be used:
orm/src/Mapping/ClassMetadataFactory.php
Lines 556 to 558 in 1072ea6