Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pg_get_serial_sequence to detect auto incrementing columns #1119

Open
koskimas opened this issue Aug 15, 2024 · 0 comments
Open

Use pg_get_serial_sequence to detect auto incrementing columns #1119

koskimas opened this issue Aug 15, 2024 · 0 comments
Labels
built-in dialect Related to a built-in dialect enhancement New feature or request postgres Related to PostgreSQL

Comments

@koskimas
Copy link
Member

koskimas commented Aug 15, 2024

We currently have our own hacky version of this detection on postgres that fails if someone renames the column.

CREATE TABLE foo (id SERIAL, val TEXT);
SELECT pg_get_serial_sequence('foo', 'id'); 
-- 'public.foo_id_seq'
ALTER TABLE foo RENAME COLUMN id TO identifier;
SELECT pg_get_serial_sequence('foo', 'identifier');
-- 'public.foo_id_seq' <-- this is correct! The sequence is not renamed
SELECT pg_get_serial_sequence('foo', 'val');
-- NULL
@koskimas koskimas added enhancement New feature or request postgres Related to PostgreSQL built-in dialect Related to a built-in dialect labels Aug 15, 2024
@koskimas koskimas changed the title Use pg_get_serial_sequence to detect primary key Use pg_get_serial_sequence to detect auto incrementing columns Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
built-in dialect Related to a built-in dialect enhancement New feature or request postgres Related to PostgreSQL
Projects
None yet
Development

No branches or pull requests

1 participant