BigQuery: Parse optional DELETE FROM statement (#1120)

This commit is contained in:
Ifeanyi Ubah 2024-02-04 14:57:33 +01:00 committed by GitHub
parent 61089f977c
commit df738f9b10
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 120 additions and 27 deletions

View file

@ -6324,12 +6324,18 @@ impl<'a> Parser<'a> {
}
pub fn parse_delete(&mut self) -> Result<Statement, ParserError> {
let tables = if !self.parse_keyword(Keyword::FROM) {
let tables = self.parse_comma_separated(|p| p.parse_object_name(false))?;
self.expect_keyword(Keyword::FROM)?;
tables
let (tables, with_from_keyword) = if !self.parse_keyword(Keyword::FROM) {
// `FROM` keyword is optional in BigQuery SQL.
// https://cloud.google.com/bigquery/docs/reference/standard-sql/dml-syntax#delete_statement
if dialect_of!(self is BigQueryDialect | GenericDialect) {
(vec![], false)
} else {
let tables = self.parse_comma_separated(|p| p.parse_object_name(false))?;
self.expect_keyword(Keyword::FROM)?;
(tables, true)
}
} else {
vec![]
(vec![], true)
};
let from = self.parse_comma_separated(Parser::parse_table_and_joins)?;
@ -6361,7 +6367,11 @@ impl<'a> Parser<'a> {
Ok(Statement::Delete {
tables,
from,
from: if with_from_keyword {
FromTable::WithFromKeyword(from)
} else {
FromTable::WithoutKeyword(from)
},
using,
selection,
returning,