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

feat: support SET TIME ZONE INTERVAL '+00:00' HOUR TO MINUTE; #18705

Merged
merged 5 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 connectors 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;
21 changes: 21 additions & 0 deletions src/sqlparser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4286,9 +4286,30 @@ impl Parser<'_> {
pub fn parse_set(&mut self) -> PResult<Statement> {
let modifier = self.parse_one_of_keywords(&[Keyword::SESSION, Keyword::LOCAL]);
if self.parse_keywords(&[Keyword::TIME, Keyword::ZONE]) {
// add support for SET TIME ZONE INTERVAL '+00:00' HOUR TO MINUTE;
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 connectors which would send when initializing the connection
chenzl25 marked this conversation as resolved.
Show resolved Hide resolved
// 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
Loading