Snowflake: Support CREATE VIEW myview IF NOT EXISTS#1961
Hidden character warning
Conversation
| Box::new(BigQueryDialect {}), | ||
| ]); | ||
| let _ = dialects.verified_stmt(sql); | ||
| let sql = "CREATE VIEW v IF NOT EXISTS AS SELECT 1"; |
There was a problem hiding this comment.
From a quick look I couldn't find which dialects in practice support this syntax? Do you have a link to documentation for one such dialect?
related the MR not super sure it would be necessary to have this behavior covered by a flag and the parser can always look to accept CREATE VIEW IF NOT EXISTS v, as well as the other syntax if its relevant)
There was a problem hiding this comment.
You're right, I couldn't find official documentation for this syntax, though we have confirmed it works in practice on Snowflake.
I'm happy to remove the dialect flag and update the parser to support both forms for all dialects. Let me know if you'd like me to proceed with that change.
There was a problem hiding this comment.
Ah yeah in that case I think we can remove the dialect flags, not sure that we need to support both forms if CREATE VIEW v IF NOT EXISTS is not supported by any dialect
There was a problem hiding this comment.
It's supported in snowflake, but not officially documented.
There was a problem hiding this comment.
Ah alright, in that case yeah I think we could skip the dialect methods entirely and let the parser accept either format if they show up? Also we can add a comment flagging that the second format is supported by snowflake but is undocumented
…, also added ability to write view name before if not exists in snowflake as it is implemented, replaced dialect of with trait functions
…t exists supported by snowflake
6f60343 to
46ce27f
Compare
| // 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 allow_unquoted_hyphen = dialect_of!(self is BigQueryDialect); | ||
| let name = self.parse_object_name(allow_unquoted_hyphen)?; |
There was a problem hiding this comment.
Would it work to only put something like this line after we've parsed? name
let name_before_not_exists = !if_not_exists && self.parse_keywords(&[Keyword::IF, Keyword::NOT, Keyword::EXISTS]);
let if_not_exists = if_not_exists || name_before_not_exists;thinking if so that would let us avoid the if/else and mut
| let sql: &'static str = "CREATE VIEW IF NOT EXISTS v AS SELECT 1"; | ||
| let _ = all_dialects().verified_stmt(sql); | ||
| let sql = "CREATE VIEW v IF NOT EXISTS AS SELECT 1"; | ||
| let _ = all_dialects().verified_stmt(sql); |
There was a problem hiding this comment.
Can we add a test case for CREATE VIEW IF NOT EXISTS AS SELECT 1 to verify how the parser behaves in that scenario?
| materialized: bool, | ||
| /// View name | ||
| name: ObjectName, | ||
| // Name IF NOT EXIST instead of IF NOT EXIST name |
There was a problem hiding this comment.
| // Name IF NOT EXIST instead of IF NOT EXIST name | |
| /// If `if_not_exists` is true, this flag is set to true if the view name comes before the `IF NOT EXISTS` clause. | |
| /// Example: | |
| /// ```sql | |
| /// CREATE VIEW myview IF NOT EXISTS AS SELECT 1` | |
| /// ``` | |
| /// Otherwise, the flag is set to false if the view name comes after the clause | |
| /// Example: | |
| /// ```sql | |
| /// CREATE VIEW IF NOT EXISTS myview AS SELECT 1` | |
| /// ``` |
we could say something descriptive like this?
CREATE VIEW myview IF NOT EXISTS
iffyio
left a comment
There was a problem hiding this comment.
LGTM! Thanks @etgarperets!
cc @alamb
…, also added ability to write view name before if not exists in snowflake as it is implemented, replaced dialect of with trait functions