Skip to content

Commit 45420ce

Browse files
romanbRoman Borschel
and
Roman Borschel
authored
Fix: Snowflake ALTER SESSION cannot be followed by other statements. (apache#1786)
Co-authored-by: Roman Borschel <[email protected]>
1 parent 25bb871 commit 45420ce

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

src/dialect/snowflake.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -1013,9 +1013,15 @@ fn parse_session_options(
10131013
let mut options: Vec<KeyValueOption> = Vec::new();
10141014
let empty = String::new;
10151015
loop {
1016-
match parser.next_token().token {
1017-
Token::Comma => continue,
1016+
let next_token = parser.peek_token();
1017+
match next_token.token {
1018+
Token::SemiColon | Token::EOF => break,
1019+
Token::Comma => {
1020+
parser.advance_token();
1021+
continue;
1022+
}
10181023
Token::Word(key) => {
1024+
parser.advance_token();
10191025
if set {
10201026
let option = parse_option(parser, key)?;
10211027
options.push(option);
@@ -1028,10 +1034,7 @@ fn parse_session_options(
10281034
}
10291035
}
10301036
_ => {
1031-
if parser.peek_token().token == Token::EOF {
1032-
break;
1033-
}
1034-
return parser.expected("another option", parser.peek_token());
1037+
return parser.expected("another option or end of statement", next_token);
10351038
}
10361039
}
10371040
}

tests/sqlparser_snowflake.rs

+11
Original file line numberDiff line numberDiff line change
@@ -3505,3 +3505,14 @@ fn test_alter_session() {
35053505
);
35063506
snowflake().one_statement_parses_to("ALTER SESSION UNSET a\nB", "ALTER SESSION UNSET a, B");
35073507
}
3508+
3509+
#[test]
3510+
fn test_alter_session_followed_by_statement() {
3511+
let stmts = snowflake()
3512+
.parse_sql_statements("ALTER SESSION SET QUERY_TAG='hello'; SELECT 42")
3513+
.unwrap();
3514+
match stmts[..] {
3515+
[Statement::AlterSession { .. }, Statement::Query { .. }] => {}
3516+
_ => panic!("Unexpected statements: {:?}", stmts),
3517+
}
3518+
}

0 commit comments

Comments
 (0)