From c58a8a0b4bd75240c85ab51650a9d024b66d6ab1 Mon Sep 17 00:00:00 2001 From: Dylan Chen Date: Wed, 25 Sep 2024 15:36:20 +0800 Subject: [PATCH 1/4] support SET TIME ZONE INTERVAL '+00:00' HOUR TO MINUTE; --- e2e_test/database/timezone.slt | 4 ++++ src/sqlparser/src/parser.rs | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/e2e_test/database/timezone.slt b/e2e_test/database/timezone.slt index 5ee196a8bf17d..20691deeb0fd4 100644 --- a/e2e_test/database/timezone.slt +++ b/e2e_test/database/timezone.slt @@ -71,3 +71,7 @@ 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; \ No newline at end of file diff --git a/src/sqlparser/src/parser.rs b/src/sqlparser/src/parser.rs index 1ee9b06392164..2450448ca32d8 100644 --- a/src/sqlparser/src/parser.rs +++ b/src/sqlparser/src/parser.rs @@ -4286,9 +4286,30 @@ impl Parser<'_> { pub fn parse_set(&mut self) -> PResult { 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 + // 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), )) From 70202026ce6c4897fcf2d32c06113300932cadb0 Mon Sep 17 00:00:00 2001 From: Dylan Chen Date: Wed, 25 Sep 2024 15:38:27 +0800 Subject: [PATCH 2/4] add tests --- e2e_test/database/timezone.slt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/e2e_test/database/timezone.slt b/e2e_test/database/timezone.slt index 20691deeb0fd4..3f548b62cc05a 100644 --- a/e2e_test/database/timezone.slt +++ b/e2e_test/database/timezone.slt @@ -74,4 +74,8 @@ 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; \ No newline at end of file +SET TIME ZONE INTERVAL '+00:00' HOUR TO MINUTE; + +# only support '+00:00' +statement error +SET TIME ZONE INTERVAL '+01:00' HOUR TO MINUTE; \ No newline at end of file From 20888b0421f0ef4a63684c2c771d9831f931f561 Mon Sep 17 00:00:00 2001 From: Dylan Chen Date: Wed, 25 Sep 2024 15:56:03 +0800 Subject: [PATCH 3/4] refine --- src/sqlparser/src/parser.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/sqlparser/src/parser.rs b/src/sqlparser/src/parser.rs index 2450448ca32d8..9ec83a845de3a 100644 --- a/src/sqlparser/src/parser.rs +++ b/src/sqlparser/src/parser.rs @@ -4286,7 +4286,6 @@ impl Parser<'_> { pub fn parse_set(&mut self) -> PResult { 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), From 3d668bf2455ea41394302e34ad34f6f5e66d0f1c Mon Sep 17 00:00:00 2001 From: Dylan Chen Date: Wed, 25 Sep 2024 16:16:07 +0800 Subject: [PATCH 4/4] refine --- e2e_test/database/timezone.slt | 2 +- src/sqlparser/src/parser.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e_test/database/timezone.slt b/e2e_test/database/timezone.slt index 3f548b62cc05a..6a223c453bc0d 100644 --- a/e2e_test/database/timezone.slt +++ b/e2e_test/database/timezone.slt @@ -72,7 +72,7 @@ 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 +# support a special case for clients which would send when initializing the connection statement ok SET TIME ZONE INTERVAL '+00:00' HOUR TO MINUTE; diff --git a/src/sqlparser/src/parser.rs b/src/sqlparser/src/parser.rs index 9ec83a845de3a..061446e588d38 100644 --- a/src/sqlparser/src/parser.rs +++ b/src/sqlparser/src/parser.rs @@ -4292,7 +4292,7 @@ impl Parser<'_> { 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 + // 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, .. } => {