Skip to content

Commit fccae77

Browse files
authored
support "set time zone to 'some-timezone'" (#617)
* support "set time zone" * fix clippy * fix test cases
1 parent 48fa79d commit fccae77

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

src/parser.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3774,7 +3774,12 @@ impl<'a> Parser<'a> {
37743774
});
37753775
}
37763776

3777-
let variable = self.parse_object_name()?;
3777+
let variable = if self.parse_keywords(&[Keyword::TIME, Keyword::ZONE]) {
3778+
ObjectName(vec!["TIMEZONE".into()])
3779+
} else {
3780+
self.parse_object_name()?
3781+
};
3782+
37783783
if variable.to_string().eq_ignore_ascii_case("NAMES")
37793784
&& dialect_of!(self is MySqlDialect | GenericDialect)
37803785
{

tests/sqlparser_common.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4663,6 +4663,52 @@ fn parse_set_transaction() {
46634663
}
46644664
}
46654665

4666+
#[test]
4667+
fn parse_set_variable() {
4668+
match verified_stmt("SET SOMETHING = '1'") {
4669+
Statement::SetVariable {
4670+
local,
4671+
hivevar,
4672+
variable,
4673+
value,
4674+
} => {
4675+
assert!(!local);
4676+
assert!(!hivevar);
4677+
assert_eq!(variable, ObjectName(vec!["SOMETHING".into()]));
4678+
assert_eq!(
4679+
value,
4680+
vec![Expr::Value(Value::SingleQuotedString("1".into()))]
4681+
);
4682+
}
4683+
_ => unreachable!(),
4684+
}
4685+
4686+
one_statement_parses_to("SET SOMETHING TO '1'", "SET SOMETHING = '1'");
4687+
}
4688+
4689+
#[test]
4690+
fn parse_set_time_zone() {
4691+
match verified_stmt("SET TIMEZONE = 'UTC'") {
4692+
Statement::SetVariable {
4693+
local,
4694+
hivevar,
4695+
variable,
4696+
value,
4697+
} => {
4698+
assert!(!local);
4699+
assert!(!hivevar);
4700+
assert_eq!(variable, ObjectName(vec!["TIMEZONE".into()]));
4701+
assert_eq!(
4702+
value,
4703+
vec![Expr::Value(Value::SingleQuotedString("UTC".into()))]
4704+
);
4705+
}
4706+
_ => unreachable!(),
4707+
}
4708+
4709+
one_statement_parses_to("SET TIME ZONE TO 'UTC'", "SET TIMEZONE = 'UTC'");
4710+
}
4711+
46664712
#[test]
46674713
fn parse_commit() {
46684714
match verified_stmt("COMMIT") {

0 commit comments

Comments
 (0)