Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 10 additions & 0 deletions src/dialect/bigquery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::ast::Statement;
use crate::dialect::Dialect;
use crate::keywords::Keyword;
use crate::parser::{Parser, ParserError};
use crate::tokenizer::Token;

/// These keywords are disallowed as column identifiers. Such that
/// `SELECT 5 AS <col> FROM T` is rejected by BigQuery.
Expand Down Expand Up @@ -47,6 +48,15 @@ pub struct BigQueryDialect;
impl Dialect for BigQueryDialect {
fn parse_statement(&self, parser: &mut Parser) -> Option<Result<Statement, ParserError>> {
if parser.parse_keyword(Keyword::BEGIN) {
if parser.peek_keyword(Keyword::TRANSACTION) {
parser.prev_token();
return None;
}
let peek_token = parser.peek_token_ref();
if peek_token.token == Token::SemiColon || peek_token.token == Token::EOF {
parser.prev_token();
return None;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we merge both blocks with something like if parse.parse_keyword(BEGIN) || peek_token.token == SemiColon || peek_token.token == EOF

return Some(parser.parse_begin_exception_end());
}

Expand Down
11 changes: 11 additions & 0 deletions tests/sqlparser_bigquery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2566,3 +2566,14 @@ fn test_struct_trailing_and_nested_bracket() {
)
);
}

// https://cloud.google.com/bigquery/docs/reference/standard-sql/procedural-language#begin_transaction
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// https://cloud.google.com/bigquery/docs/reference/standard-sql/procedural-language#begin_transaction

#[test]
fn test_begin_transaction() {
bigquery().verified_stmt("BEGIN TRANSACTION");
}

#[test]
fn test_begin_statement() {
bigquery().verified_stmt("BEGIN");
}
Loading