Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/ast/ddl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4277,6 +4277,9 @@ pub struct CreateView {
pub if_not_exists: bool,
/// if true, has SQLite `TEMP` or `TEMPORARY` clause <https://www.sqlite.org/lang_createview.html>
pub temporary: bool,
/// Snowflake: `COPY GRANTS` clause
/// <https://docs.snowflake.com/en/sql-reference/sql/create-view>
pub copy_grants: bool,
/// if not None, has Clickhouse `TO` clause, specify the table into which to insert results
/// <https://clickhouse.com/docs/en/sql-reference/statements/create/view#materialized-view>
pub to: Option<ObjectName>,
Expand Down Expand Up @@ -4320,6 +4323,9 @@ impl fmt::Display for CreateView {
.map(|to| format!(" TO {to}"))
.unwrap_or_default()
)?;
if self.copy_grants {
write!(f, " COPY GRANTS")?;
}
if !self.columns.is_empty() {
write!(f, " ({})", display_comma_separated(&self.columns))?;
}
Expand Down
2 changes: 2 additions & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6375,6 +6375,7 @@ impl<'a> Parser<'a> {
let name_before_not_exists = !if_not_exists_first
&& self.parse_keywords(&[Keyword::IF, Keyword::NOT, Keyword::EXISTS]);
let if_not_exists = if_not_exists_first || name_before_not_exists;
let copy_grants = self.parse_keywords(&[Keyword::COPY, Keyword::GRANTS]);
// Many dialects support `OR ALTER` right after `CREATE`, but we don't (yet).
// ANSI SQL and Postgres support RECURSIVE here, but we don't support it either.
let columns = self.parse_view_columns()?;
Expand Down Expand Up @@ -6442,6 +6443,7 @@ impl<'a> Parser<'a> {
with_no_schema_binding,
if_not_exists,
temporary,
copy_grants,
to,
params: create_view_params,
name_before_not_exists,
Expand Down
6 changes: 6 additions & 0 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8317,6 +8317,7 @@ fn parse_create_view() {
params,
name_before_not_exists: _,
secure: _,
copy_grants: _,
}) => {
assert_eq!(or_alter, false);
assert_eq!("myschema.myview", name.to_string());
Expand Down Expand Up @@ -8435,6 +8436,7 @@ fn parse_create_view_temporary() {
params,
name_before_not_exists: _,
secure: _,
copy_grants: _,
}) => {
assert_eq!(or_alter, false);
assert_eq!("myschema.myview", name.to_string());
Expand Down Expand Up @@ -8476,6 +8478,7 @@ fn parse_create_or_replace_view() {
params,
name_before_not_exists: _,
secure: _,
copy_grants: _,
}) => {
assert_eq!(or_alter, false);
assert_eq!("v", name.to_string());
Expand Down Expand Up @@ -8521,6 +8524,7 @@ fn parse_create_or_replace_materialized_view() {
params,
name_before_not_exists: _,
secure: _,
copy_grants: _,
}) => {
assert_eq!(or_alter, false);
assert_eq!("v", name.to_string());
Expand Down Expand Up @@ -8562,6 +8566,7 @@ fn parse_create_materialized_view() {
params,
name_before_not_exists: _,
secure: _,
copy_grants: _,
}) => {
assert_eq!(or_alter, false);
assert_eq!("myschema.myview", name.to_string());
Expand Down Expand Up @@ -8603,6 +8608,7 @@ fn parse_create_materialized_view_with_cluster_by() {
params,
name_before_not_exists: _,
secure: _,
copy_grants: _,
}) => {
assert_eq!(or_alter, false);
assert_eq!("myschema.myview", name.to_string());
Expand Down
11 changes: 11 additions & 0 deletions tests/sqlparser_snowflake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4650,6 +4650,17 @@ fn test_snowflake_create_view_with_composite_policy_name() {
snowflake().verified_stmt(create_view_with_tag);
}

#[test]
fn test_snowflake_create_view_copy_grants() {
snowflake().verified_stmt("CREATE OR REPLACE VIEW bla COPY GRANTS AS (SELECT * FROM source)");
snowflake()
.verified_stmt("CREATE OR REPLACE SECURE VIEW bla COPY GRANTS AS (SELECT * FROM source)");
// COPY GRANTS with column list
snowflake().verified_stmt(
"CREATE OR REPLACE VIEW bla COPY GRANTS (a, b) AS (SELECT a, b FROM source)",
);
}

#[test]
fn test_snowflake_identifier_function() {
// Using IDENTIFIER to reference a column
Expand Down