nextras / dbal

Database Abstraction Layer – concise secure API to construct queries & fetch data
https://nextras.org/dbal
MIT License
79 stars 28 forks source link

Support PostgreSQL identity columns #233

Closed jiripudil closed 8 months ago

jiripudil commented 8 months ago

Currently PostgreSqlPlatform only recognizes serial columns. However, PostgreSQL 10+ supports SQL-standard identity columns:

CREATE TABLE test (
  id integer GENERATED ALWAYS AS IDENTITY PRIMARY KEY
)

These only have implicit sequences that PostgreSqlPlatform currently cannot reflect, and thus the driver cannot fetch the last inserted id.

The pg_get_serial_sequence function seems to work for both serial columns, and identity columns, so perhaps it could be used to get the attached sequence name in PostgreSqlPlatform. And, for completeness sake, the is_autoincrement column should also check whether a.attidentity != ''