Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support "set time zone to 'some-timezone'" #617

Merged
merged 3 commits into from Sep 20, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/parser.rs
Expand Up @@ -3774,7 +3774,12 @@ impl<'a> Parser<'a> {
});
}

let variable = self.parse_object_name()?;
let variable = if self.parse_keywords(&[Keyword::TIME, Keyword::ZONE]) {
ObjectName(vec!["TIMEZONE".into()])
} else {
self.parse_object_name()?
};

if variable.to_string().eq_ignore_ascii_case("NAMES")
&& dialect_of!(self is MySqlDialect | GenericDialect)
{
Expand Down
46 changes: 46 additions & 0 deletions tests/sqlparser_common.rs
Expand Up @@ -4663,6 +4663,52 @@ fn parse_set_transaction() {
}
}

#[test]
fn parse_set_variable() {
match verified_stmt("SET SOMETHING = '1'") {
Statement::SetVariable {
local,
hivevar,
variable,
value,
} => {
assert!(!local);
assert!(!hivevar);
assert_eq!(variable, ObjectName(vec!["SOMETHING".into()]));
assert_eq!(
value,
vec![Expr::Value(Value::SingleQuotedString("1".into()))]
);
}
_ => unreachable!(),
}

one_statement_parses_to("SET SOMETHING TO '1'", "SET SOMETHING = '1'");
}

#[test]
fn parse_set_time_zone() {
match verified_stmt("SET TIMEZONE = 'UTC'") {
Statement::SetVariable {
local,
hivevar,
variable,
value,
} => {
assert!(!local);
assert!(!hivevar);
assert_eq!(variable, ObjectName(vec!["TIMEZONE".into()]));
assert_eq!(
value,
vec![Expr::Value(Value::SingleQuotedString("UTC".into()))]
);
}
_ => unreachable!(),
}

one_statement_parses_to("SET TIME ZONE TO 'UTC'", "SET TIMEZONE = 'UTC'");
}
Comment on lines +4689 to +4710
Copy link
Contributor Author

Choose a reason for hiding this comment

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

test case for both TIME ZONE and TIMEZONE


#[test]
fn parse_commit() {
match verified_stmt("COMMIT") {
Expand Down