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

Add PostgreSql alter column sequence parameters #4916

Conversation

griffio
Copy link
Contributor

@griffio griffio commented Dec 16, 2023

👻 Adds the missing sequence parameters when creating and updating identity columns.

These are shared with CREATE SEQUENCE parameters (except RESTART WITH)

ALTER TABLE t1
    ALTER COLUMN c1 ADD GENERATED ALWAYS AS IDENTITY (
      SEQUENCE NAME t1_seq
      INCREMENT BY 10
      MINVALUE 100
      MAXVALUE 9223372
      START 1
      CACHE 20
      NO CYCLE
    );

Add parameters for SET - similar to ALTER SEQUENCE also not implemented yet

ALTER TABLE contact ALTER COLUMN contact_id
SET GENERATED ALWAYS -- BY DEFAULT
SET INCREMENT 1
SET MINVALUE  1
SET MAXVALUE  11
SET NO MINVALUE
SET START WITH 1
SET CACHE 111
SET  NO  CYCLE
RESTART WITH 1

The changes also adds to CREATE TABLE with sequence parameters support as share grammar

CREATE TABLE t1 (
  c1 INTEGER GENERATED ALWAYS AS IDENTITY (
      SEQUENCE NAME t1_seq
      INCREMENT BY 10
      MINVALUE 11
      MAXVALUE 44444
      START 11
      CACHE 20
      NO CYCLE
    ),
  c2 INTEGER DEFAULT 0,
  c3 VARCHAR(25),
  c4 TEXT,
  c5 NUMERIC(10, 2)
);

Adds the missing sequence parameters to identity coloumns
ALTER COLUMN allows multiple sequential SET clauses for identity columns
The grammar seems very tricky so this is a best effort to have it working

Add more fixture tests to show syntax
Change sequence_parameters to use pin=2
Do this seems to allow the sequence_parameters to be declared in any order
@griffio griffio marked this pull request as ready for review December 20, 2023 20:07
@AlecKazakova AlecKazakova merged commit 96f4329 into cashapp:master Jan 29, 2024
7 checks passed
@griffio griffio deleted the add-postgresql-alter-column-identity-options branch January 29, 2024 21:17
hfhbd pushed a commit that referenced this pull request Apr 2, 2024
* Add PostgreSql alter column sequence parameters

Adds the missing sequence parameters to identity coloumns

* Add SET for identity columns

ALTER COLUMN allows multiple sequential SET clauses for identity columns
The grammar seems very tricky so this is a best effort to have it working

Add more fixture tests to show syntax

* Update PostgreSql.bnf sequence_parameters

Change sequence_parameters to use pin=2
Do this seems to allow the sequence_parameters to be declared in any order
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants