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

Postgres: Allow use of quoted identifiers to ALTER TABLE OWNER TO #1856

Merged
merged 3 commits into from Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/sqlfluff/dialects/dialect_postgres.py
Expand Up @@ -1269,7 +1269,12 @@ class AlterTableActionSegment(BaseSegment):
Sequence(
"OWNER",
"TO",
OneOf(Ref("ParameterNameSegment"), "CURRENT_USER", "SESSION_USER"),
OneOf(
OneOf(Ref("ParameterNameSegment"), Ref("QuotedIdentifierSegment")),
"CURRENT_ROLE",
"CURRENT_USER",
"SESSION_USER",
),
),
Sequence(
"REPLICA",
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/dialects/postgres/postgres_alter_table.sql
Expand Up @@ -92,3 +92,9 @@ ALTER TABLE distributors ALTER COLUMN street ADD GENERATED ALWAYS AS IDENTITY (I
ALTER TABLE distributors ALTER COLUMN street SET RESTART WITH 3;

ALTER TABLE distributors ADD my_column int GENERATED BY DEFAULT AS IDENTITY (CACHE 3 MAXVALUE 63 OWNED BY NONE);

ALTER TABLE public.test OWNER TO "ID";

ALTER TABLE public.test OWNER TO ID;

ALTER TABLE IF EXISTS ONLY public.test OWNER TO CURRENT_ROLE;
44 changes: 43 additions & 1 deletion test/fixtures/dialects/postgres/postgres_alter_table.yml
Expand Up @@ -3,7 +3,7 @@
# computed by SQLFluff when running the tests. Please run
# `python test/generate_parse_fixture_yml.py` to generate them after adding or
# altering SQL files.
_hash: 264cddb2818c93bf82d95c4cd2a9ad35998aea040cba3ce7ec840dd50c3ad71b
_hash: 12d249090b77cfdf9b99daeddd63ed7b336cf12b646e411dfbc0693ac0b75977
file:
- statement:
alter_table_statement:
Expand Down Expand Up @@ -767,3 +767,45 @@ file:
- keyword: NONE
- end_bracket: )
- statement_terminator: ;
- statement:
alter_table_statement:
- keyword: ALTER
- keyword: TABLE
- table_reference:
- identifier: public
- dot: .
- identifier: test
- alter_table_action_segment:
- keyword: OWNER
- keyword: TO
- identifier: '"ID"'
- statement_terminator: ;
- statement:
alter_table_statement:
- keyword: ALTER
- keyword: TABLE
- table_reference:
- identifier: public
- dot: .
- identifier: test
- alter_table_action_segment:
- keyword: OWNER
- keyword: TO
- parameter: ID
- statement_terminator: ;
- statement:
alter_table_statement:
- keyword: ALTER
- keyword: TABLE
- keyword: IF
- keyword: EXISTS
- keyword: ONLY
- table_reference:
- identifier: public
- dot: .
- identifier: test
- alter_table_action_segment:
- keyword: OWNER
- keyword: TO
- parameter: CURRENT_ROLE
- statement_terminator: ;