Skip to content

Commit

Permalink
feat: support SET TIME ZONE INTERVAL '+00:00' HOUR TO MINUTE; (#18705)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenzl25 authored Sep 25, 2024
1 parent 9629fdd commit 9aa26bd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions e2e_test/database/timezone.slt
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,11 @@ set time zone 12.3;

statement error
set time zone interval '1' hour;

# support a special case for clients which would send when initializing the connection
statement ok
SET TIME ZONE INTERVAL '+00:00' HOUR TO MINUTE;

# only support '+00:00'
statement error
SET TIME ZONE INTERVAL '+01:00' HOUR TO MINUTE;
20 changes: 20 additions & 0 deletions src/sqlparser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4289,6 +4289,26 @@ impl Parser<'_> {
let value = alt((
Keyword::DEFAULT.value(SetTimeZoneValue::Default),
Keyword::LOCAL.value(SetTimeZoneValue::Local),
preceded(
Keyword::INTERVAL,
cut_err(Self::parse_literal_interval.try_map(|e| match e {
// support a special case for clients which would send when initializing the connection
// like: SET TIME ZONE INTERVAL '+00:00' HOUR TO MINUTE;
Expr::Value(v) => match v {
Value::Interval { value, .. } => {
if value != "+00:00" {
return Err(StrError("only support \"+00:00\" ".into()));
}
Ok(SetTimeZoneValue::Ident(Ident::with_quote_unchecked(
'\'',
"UTC".to_string(),
)))
}
_ => Err(StrError("expect Value::Interval".into())),
},
_ => Err(StrError("expect Expr::Value".into())),
})),
),
Self::parse_identifier.map(SetTimeZoneValue::Ident),
Self::parse_value.map(SetTimeZoneValue::Literal),
))
Expand Down

0 comments on commit 9aa26bd

Please sign in to comment.