mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-26 17:04:10 +00:00
add set time zone sometimezone as a exception while parsing keyword::set (#727)
* add set time zone sometimezone as a exception while parsing keyword::set * remove redundant parentheses * add Statement::SetTimeZone * delete useless comments
This commit is contained in:
parent
10652b61b4
commit
bae682255d
3 changed files with 32 additions and 0 deletions
|
@ -1271,6 +1271,11 @@ pub enum Statement {
|
|||
variable: ObjectName,
|
||||
value: Vec<Expr>,
|
||||
},
|
||||
/// SET TIME ZONE <value>
|
||||
///
|
||||
/// Note: this is a PostgreSQL-specific statements
|
||||
/// SET TIME ZONE <value> is an alias for SET timezone TO <value> in PostgreSQL
|
||||
SetTimeZone { local: bool, value: Expr },
|
||||
/// SET NAMES 'charset_name' [COLLATE 'collation_name']
|
||||
///
|
||||
/// Note: this is a MySQL-specific statement.
|
||||
|
@ -2228,6 +2233,13 @@ impl fmt::Display for Statement {
|
|||
value = display_comma_separated(value)
|
||||
)
|
||||
}
|
||||
Statement::SetTimeZone { local, value } => {
|
||||
f.write_str("SET ")?;
|
||||
if *local {
|
||||
f.write_str("LOCAL ")?;
|
||||
}
|
||||
write!(f, "TIME ZONE {value}")
|
||||
}
|
||||
Statement::SetNames {
|
||||
charset_name,
|
||||
collation_name,
|
||||
|
|
|
@ -4551,6 +4551,15 @@ impl<'a> Parser<'a> {
|
|||
value: values,
|
||||
});
|
||||
}
|
||||
} else if variable.to_string().eq_ignore_ascii_case("TIMEZONE") {
|
||||
// for some db (e.g. postgresql), SET TIME ZONE <value> is an alias for SET TIMEZONE [TO|=] <value>
|
||||
match self.parse_expr() {
|
||||
Ok(expr) => Ok(Statement::SetTimeZone {
|
||||
local: modifier == Some(Keyword::LOCAL),
|
||||
value: expr,
|
||||
}),
|
||||
_ => self.expected("timezone value", self.peek_token())?,
|
||||
}
|
||||
} else if variable.to_string() == "CHARACTERISTICS" {
|
||||
self.expect_keywords(&[Keyword::AS, Keyword::TRANSACTION])?;
|
||||
Ok(Statement::SetTransaction {
|
||||
|
|
|
@ -4979,6 +4979,17 @@ fn parse_set_time_zone() {
|
|||
one_statement_parses_to("SET TIME ZONE TO 'UTC'", "SET TIMEZONE = 'UTC'");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_set_time_zone_alias() {
|
||||
match verified_stmt("SET TIME ZONE 'UTC'") {
|
||||
Statement::SetTimeZone { local, value } => {
|
||||
assert!(!local);
|
||||
assert_eq!(value, Expr::Value(Value::SingleQuotedString("UTC".into())));
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_commit() {
|
||||
match verified_stmt("COMMIT") {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue