Skip to content
Merged
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
10 changes: 6 additions & 4 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3527,7 +3527,8 @@ impl<'a> Parser<'a> {
&& self.parse_keywords(&[Keyword::IF, Keyword::NOT, Keyword::EXISTS]);
// 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 name = self.parse_object_name(false)?;
let allow_unquoted_hyphen = dialect_of!(self is BigQueryDialect);
let name = self.parse_object_name(allow_unquoted_hyphen)?;
let columns = self.parse_view_columns()?;
let mut options = CreateTableOptions::None;
let with_options = self.parse_options(Keyword::WITH)?;
Expand Down Expand Up @@ -4482,8 +4483,9 @@ impl<'a> Parser<'a> {
global: Option<bool>,
transient: bool,
) -> Result<Statement, ParserError> {
let allow_unquoted_hyphen = dialect_of!(self is BigQueryDialect);
let if_not_exists = self.parse_keywords(&[Keyword::IF, Keyword::NOT, Keyword::EXISTS]);
let table_name = self.parse_object_name(false)?;
let table_name = self.parse_object_name(allow_unquoted_hyphen)?;

// Clickhouse has `ON CLUSTER 'cluster'` syntax for DDLs
let on_cluster = if self.parse_keywords(&[Keyword::ON, Keyword::CLUSTER]) {
Expand All @@ -4498,13 +4500,13 @@ impl<'a> Parser<'a> {
};

let like = if self.parse_keyword(Keyword::LIKE) || self.parse_keyword(Keyword::ILIKE) {
self.parse_object_name(false).ok()
self.parse_object_name(allow_unquoted_hyphen).ok()
} else {
None
};

let clone = if self.parse_keyword(Keyword::CLONE) {
self.parse_object_name(false).ok()
self.parse_object_name(allow_unquoted_hyphen).ok()
} else {
None
};
Expand Down
45 changes: 45 additions & 0 deletions tests/sqlparser_bigquery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,51 @@ fn parse_create_view_if_not_exists() {
}
}

#[test]
fn parse_create_view_with_unquoted_hyphen() {
let sql = "CREATE VIEW IF NOT EXISTS my-pro-ject.mydataset.myview AS SELECT 1";
match bigquery().verified_stmt(sql) {
Statement::CreateView {
name,
query,
if_not_exists,
..
} => {
assert_eq!("my-pro-ject.mydataset.myview", name.to_string());
assert_eq!("SELECT 1", query.to_string());
assert!(if_not_exists);
}
_ => unreachable!(),
}
}

#[test]
fn parse_create_table_with_unquoted_hyphen() {
let sql = "CREATE TABLE my-pro-ject.mydataset.mytable (x INT64)";
match bigquery().verified_stmt(sql) {
Statement::CreateTable { name, columns, .. } => {
assert_eq!(
name,
ObjectName(vec![
"my-pro-ject".into(),
"mydataset".into(),
"mytable".into()
])
);
assert_eq!(
vec![ColumnDef {
name: Ident::new("x"),
data_type: DataType::Int64,
collation: None,
options: vec![]
},],
columns
);
}
_ => unreachable!(),
}
}

#[test]
fn parse_create_table_with_options() {
let sql = concat!(
Expand Down