Skip to content

Commit 299f54d

Browse files
authored
Snowflake: Accept COPY GRANTS after CREATE VIEW column list (apache#2327)
1 parent 824b5c1 commit 299f54d

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

src/parser/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6533,10 +6533,16 @@ impl<'a> Parser<'a> {
65336533
let name_before_not_exists = !if_not_exists_first
65346534
&& self.parse_keywords(&[Keyword::IF, Keyword::NOT, Keyword::EXISTS]);
65356535
let if_not_exists = if_not_exists_first || name_before_not_exists;
6536-
let copy_grants = self.parse_keywords(&[Keyword::COPY, Keyword::GRANTS]);
6536+
let mut copy_grants = self.parse_keywords(&[Keyword::COPY, Keyword::GRANTS]);
65376537
// Many dialects support `OR ALTER` right after `CREATE`, but we don't (yet).
65386538
// ANSI SQL and Postgres support RECURSIVE here, but we don't support it either.
65396539
let columns = self.parse_view_columns()?;
6540+
// Snowflake also documents `COPY GRANTS` *after* the column list; accept
6541+
// either position, but not both.
6542+
// <https://docs.snowflake.com/en/sql-reference/sql/create-view#syntax>
6543+
if !copy_grants {
6544+
copy_grants = self.parse_keywords(&[Keyword::COPY, Keyword::GRANTS]);
6545+
}
65406546
let mut options = CreateTableOptions::None;
65416547
let with_options = self.parse_options(Keyword::WITH)?;
65426548
if !with_options.is_empty() {

tests/sqlparser_snowflake.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4793,6 +4793,28 @@ fn test_snowflake_create_view_copy_grants() {
47934793
);
47944794
}
47954795

4796+
#[test]
4797+
fn test_snowflake_create_view_copy_grants_after_columns() {
4798+
let cases = [
4799+
(
4800+
"CREATE OR REPLACE VIEW v (a, b) COPY GRANTS AS SELECT a, b FROM t",
4801+
"CREATE OR REPLACE VIEW v COPY GRANTS (a, b) AS SELECT a, b FROM t",
4802+
),
4803+
(
4804+
"CREATE OR REPLACE SECURE VIEW v (a, b) COPY GRANTS AS SELECT a, b FROM t",
4805+
"CREATE OR REPLACE SECURE VIEW v COPY GRANTS (a, b) AS SELECT a, b FROM t",
4806+
),
4807+
(
4808+
"CREATE MATERIALIZED VIEW v (a) COPY GRANTS AS SELECT a FROM t",
4809+
"CREATE MATERIALIZED VIEW v COPY GRANTS (a) AS SELECT a FROM t",
4810+
),
4811+
];
4812+
for (sql, parsed) in cases {
4813+
snowflake().one_statement_parses_to(sql, parsed);
4814+
}
4815+
snowflake().verified_stmt("CREATE OR REPLACE VIEW v (a) AS SELECT a FROM t");
4816+
}
4817+
47964818
#[test]
47974819
fn test_snowflake_identifier_function() {
47984820
// Using IDENTIFIER to reference a column

0 commit comments

Comments
 (0)