Skip to content

Commit 60baea4

Browse files
authored
BigQuery: support of CREATE VIEW IF NOT EXISTS (#1118)
1 parent 8fae601 commit 60baea4

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/parser/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3482,7 +3482,7 @@ impl<'a> Parser<'a> {
34823482
) -> Result<Statement, ParserError> {
34833483
let materialized = self.parse_keyword(Keyword::MATERIALIZED);
34843484
self.expect_keyword(Keyword::VIEW)?;
3485-
let if_not_exists = dialect_of!(self is SQLiteDialect|GenericDialect)
3485+
let if_not_exists = dialect_of!(self is BigQueryDialect|SQLiteDialect|GenericDialect)
34863486
&& self.parse_keywords(&[Keyword::IF, Keyword::NOT, Keyword::EXISTS]);
34873487
// Many dialects support `OR ALTER` right after `CREATE`, but we don't (yet).
34883488
// ANSI SQL and Postgres support RECURSIVE here, but we don't support it either.

tests/sqlparser_bigquery.rs

+30
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,36 @@ fn parse_create_view_with_options() {
175175
_ => unreachable!(),
176176
}
177177
}
178+
#[test]
179+
fn parse_create_view_if_not_exists() {
180+
let sql = "CREATE VIEW IF NOT EXISTS mydataset.newview AS SELECT foo FROM bar";
181+
match bigquery().verified_stmt(sql) {
182+
Statement::CreateView {
183+
name,
184+
columns,
185+
query,
186+
or_replace,
187+
materialized,
188+
options,
189+
cluster_by,
190+
with_no_schema_binding: late_binding,
191+
if_not_exists,
192+
temporary,
193+
} => {
194+
assert_eq!("mydataset.newview", name.to_string());
195+
assert_eq!(Vec::<ViewColumnDef>::new(), columns);
196+
assert_eq!("SELECT foo FROM bar", query.to_string());
197+
assert!(!materialized);
198+
assert!(!or_replace);
199+
assert_eq!(options, CreateTableOptions::None);
200+
assert_eq!(cluster_by, vec![]);
201+
assert!(!late_binding);
202+
assert!(if_not_exists);
203+
assert!(!temporary);
204+
}
205+
_ => unreachable!(),
206+
}
207+
}
178208

179209
#[test]
180210
fn parse_create_table_with_options() {

0 commit comments

Comments
 (0)