Skip to content

Snowflake: Accept COPY GRANTS after CREATE VIEW column list#2327

Open
97nitt wants to merge 2 commits intoapache:mainfrom
97nitt:upstream/copy-grants-after-view-columns
Open

Snowflake: Accept COPY GRANTS after CREATE VIEW column list#2327
97nitt wants to merge 2 commits intoapache:mainfrom
97nitt:upstream/copy-grants-after-view-columns

Conversation

@97nitt
Copy link
Copy Markdown

@97nitt 97nitt commented Apr 28, 2026

Summary

Snowflake's CREATE VIEW syntax documents COPY GRANTS as appearing
after the column list:

CREATE OR REPLACE VIEW v (a, b) COPY GRANTS AS SELECT a, b FROM t;

The parser already accepted COPY GRANTS before the column list, but
rejected the documented post-columns position. This PR accepts either
position (but not both).

Changes

  • parse_create_view: after consuming the column list, attempt a second
    COPY GRANTS match if one wasn't already seen.
  • Display continues to emit the pre-columns form, so the post-columns input
    round-trips to the existing canonical shape.
  • Tests: cover VIEW, SECURE VIEW, and MATERIALIZED VIEW with
    post-columns COPY GRANTS, and a baseline asserting the flag is not
    spuriously set when COPY GRANTS is absent.

Test plan

  • cargo test
  • cargo fmt --check
  • cargo clippy --all-targets --all-features -- -D warnings

Snowflake documents `COPY GRANTS` as appearing after the column list on
`CREATE VIEW`. The parser already accepted it before the column list;
also accept it after, normalizing Display to the pre-columns form.
Comment thread tests/sqlparser_snowflake.rs Outdated
Comment on lines +4769 to +4773
// Snowflake's documented placement for `COPY GRANTS` on `CREATE VIEW` is
// *after* the column list. Display normalizes to the pre-columns form
// already supported, so use `one_statement_parses_to` to assert the
// post-columns input is accepted and the AST flag is set.
// <https://docs.snowflake.com/en/sql-reference/sql/create-view#syntax>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Snowflake's documented placement for `COPY GRANTS` on `CREATE VIEW` is
// *after* the column list. Display normalizes to the pre-columns form
// already supported, so use `one_statement_parses_to` to assert the
// post-columns input is accepted and the AST flag is set.
// <https://docs.snowflake.com/en/sql-reference/sql/create-view#syntax>

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread tests/sqlparser_snowflake.rs Outdated
];
for (sql, parsed) in cases {
match snowflake().one_statement_parses_to(sql, parsed) {
Statement::CreateView(CreateView {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can drop the ast assertions in the tests

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

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.

2 participants