PostgreSQL create a sequence generator automatically for the serial field(s) of a table, and it's using this naming scheme by default: <table_name>_<column_name>_seq. However, there are a couple of issues with auto-created sequences:
- when a table that contains a serial field is renamed, the auto-created sequence is not also renamed automatically
- when the name of the sequence exceeds 63 characters (the PosgreSQL identifier limit), the naming scheme above is not respected anymore
Drupal handles the sequence renaming issue on its own since 8.0.0, but in order to accommodate for sequence names that exceed 63 characters, it uses a non-standard naming scheme which has been changed in Drupal 8.6.8.
Code example
Before:
If you were previously using a custom query like this to get the current sequence number after inserting a row in a custom example table with a id serial column:
$seq = $connection->select("SELECT currval('example_id_seq'::regclass)")->execute();
After:
Starting with Drupal 8.6.8, you need to use the pg_get_serial_sequence() function in order to get the current name of the sequence instead of hard-coding it:
$seq = $connection->select("SELECT currval(pg_get_serial_sequence('{example}', 'id'))")->execute();
Additional info:
Note that even for sequences that have been created manually, using pg_get_serial_sequence() is still the recommended way for getting the current name of a sequence.