From 167fe68c681ddd2754e07743c6cd4345f5abc937 Mon Sep 17 00:00:00 2001 From: chagelo Date: Thu, 21 Nov 2024 17:35:43 +0800 Subject: [PATCH 1/5] * add function `timezone(zone, timestamptz)` Signed-off-by: chagelo --- proto/expr.proto | 1 + src/expr/impl/src/scalar/timestamptz.rs | 33 ++++++++++++++----- .../binder/expr/function/builtin_scalar.rs | 5 +-- src/frontend/src/expr/pure.rs | 1 + .../src/optimizer/plan_expr_visitor/strong.rs | 1 + src/tests/regress/data/schedule | 13 ++++---- 6 files changed, 38 insertions(+), 16 deletions(-) diff --git a/proto/expr.proto b/proto/expr.proto index e56668c990447..a91d0ac173c2f 100644 --- a/proto/expr.proto +++ b/proto/expr.proto @@ -70,6 +70,7 @@ message ExprNode { ADD_WITH_TIME_ZONE = 109; SUBTRACT_WITH_TIME_ZONE = 110; MAKE_TIMESTAMPTZ = 112; + Timezone = 116; // other functions CAST = 201; SUBSTR = 202; diff --git a/src/expr/impl/src/scalar/timestamptz.rs b/src/expr/impl/src/scalar/timestamptz.rs index 7dcc718d728ef..0855ef086f6b3 100644 --- a/src/expr/impl/src/scalar/timestamptz.rs +++ b/src/expr/impl/src/scalar/timestamptz.rs @@ -41,6 +41,14 @@ pub fn f64_sec_to_timestamptz(elem: F64) -> Result { Ok(Timestamptz::from_micros(micros)) } +#[function("at_time_zone(timestamptz, varchar) -> timestamp")] +pub fn timestamptz_at_time_zone(input: Timestamptz, time_zone: &str) -> Result { + let time_zone = Timestamptz::lookup_time_zone(time_zone).map_err(time_zone_err)?; + let instant_local = input.to_datetime_in_zone(time_zone); + let naive = instant_local.naive_local(); + Ok(Timestamp(naive)) +} + #[function("at_time_zone(timestamp, varchar) -> timestamptz")] pub fn timestamp_at_time_zone(input: Timestamp, time_zone: &str) -> Result { let time_zone = Timestamptz::lookup_time_zone(time_zone).map_err(time_zone_err)?; @@ -72,6 +80,17 @@ pub fn timestamp_at_time_zone(input: Timestamp, time_zone: &str) -> Result timestamp")] +pub fn timezone_timestamp_at_time_zone(time_zone: &str, input: Timestamp) -> Result { + timestamp_at_time_zone(input, time_zone) + .map(|timestamptz| timestamptz.to_datetime_utc().naive_utc().into()) +} + +#[function("timezone(varchar, timestamptz) -> timestamp")] +pub fn timezone_timestamptz_at_time_zone(time_zone: &str, input: Timestamptz) -> Result { + timestamptz_at_time_zone(input, time_zone) +} + #[function("cast_with_time_zone(timestamptz, varchar) -> varchar")] pub fn timestamptz_to_string( elem: Timestamptz, @@ -96,14 +115,6 @@ pub fn str_to_timestamptz(elem: &str, time_zone: &str) -> Result { }) } -#[function("at_time_zone(timestamptz, varchar) -> timestamp")] -pub fn timestamptz_at_time_zone(input: Timestamptz, time_zone: &str) -> Result { - let time_zone = Timestamptz::lookup_time_zone(time_zone).map_err(time_zone_err)?; - let instant_local = input.to_datetime_in_zone(time_zone); - let naive = instant_local.naive_local(); - Ok(Timestamp(naive)) -} - /// This operation is zone agnostic. #[function("subtract(timestamptz, timestamptz) -> interval")] pub fn timestamptz_timestamptz_sub(l: Timestamptz, r: Timestamptz) -> Result { @@ -228,6 +239,12 @@ mod tests { .for_each(|(local, zone)| { let local = local.parse().unwrap(); + let actual = timezone_timestamptz_at_time_zone(zone, usecs).unwrap(); + assert_eq!(local, actual); + + let actual = timezone_timestamp_at_time_zone(zone, local).unwrap(); + assert_eq!(Timestamp::from(usecs.to_datetime_utc().naive_utc()), actual); + let actual = timestamptz_at_time_zone(usecs, zone).unwrap(); assert_eq!(local, actual); diff --git a/src/frontend/src/binder/expr/function/builtin_scalar.rs b/src/frontend/src/binder/expr/function/builtin_scalar.rs index 66c28b0ba24d6..61892829dbf69 100644 --- a/src/frontend/src/binder/expr/function/builtin_scalar.rs +++ b/src/frontend/src/binder/expr/function/builtin_scalar.rs @@ -210,7 +210,7 @@ impl Binder { ("scale", raw_call(ExprType::Scale)), ("min_scale", raw_call(ExprType::MinScale)), ("trim_scale", raw_call(ExprType::TrimScale)), - + // date and time ( "to_timestamp", dispatch_by_len(vec![ @@ -223,8 +223,9 @@ impl Binder { ("make_date", raw_call(ExprType::MakeDate)), ("make_time", raw_call(ExprType::MakeTime)), ("make_timestamp", raw_call(ExprType::MakeTimestamp)), - ("to_date", raw_call(ExprType::CharToDate)), ("make_timestamptz", raw_call(ExprType::MakeTimestamptz)), + ("timezone", raw_call(ExprType::Timezone)), + ("to_date", raw_call(ExprType::CharToDate)), // string ("substr", raw_call(ExprType::Substr)), ("length", raw_call(ExprType::Length)), diff --git a/src/frontend/src/expr/pure.rs b/src/frontend/src/expr/pure.rs index 83a8cfa537bae..a70efbe91a79f 100644 --- a/src/frontend/src/expr/pure.rs +++ b/src/frontend/src/expr/pure.rs @@ -72,6 +72,7 @@ impl ExprVisitor for ImpureAnalyzer { | Type::CastWithTimeZone | Type::AddWithTimeZone | Type::SubtractWithTimeZone + | Type::Timezone | Type::Cast | Type::Substr | Type::Length diff --git a/src/frontend/src/optimizer/plan_expr_visitor/strong.rs b/src/frontend/src/optimizer/plan_expr_visitor/strong.rs index c53bde642ad3e..e99a3260497c8 100644 --- a/src/frontend/src/optimizer/plan_expr_visitor/strong.rs +++ b/src/frontend/src/optimizer/plan_expr_visitor/strong.rs @@ -135,6 +135,7 @@ impl Strong { | ExprType::CastWithTimeZone | ExprType::SubtractWithTimeZone | ExprType::MakeTimestamptz + | ExprType::Timezone | ExprType::Substr | ExprType::Length | ExprType::ILike diff --git a/src/tests/regress/data/schedule b/src/tests/regress/data/schedule index d1cfd9ab86253..12a55796757d7 100644 --- a/src/tests/regress/data/schedule +++ b/src/tests/regress/data/schedule @@ -7,9 +7,10 @@ # interferes with crash-recovery testing. # test: tablespace -test: boolean varchar text int2 int4 int8 float4 float8 comments -test: strings date time timestamp interval -test: case arrays delete -test: jsonb jsonb_jsonpath -test: regex -test: contrib-pgcrypto-rijndael +# test: boolean varchar text int2 int4 int8 float4 float8 comments +# test: strings date time timestamp interval +# test: case arrays delete +# test: jsonb jsonb_jsonpath +# test: regex +# test: contrib-pgcrypto-rijndael +test: timestamptz \ No newline at end of file From 1de7921b2029c9f44b1f00e342d6406b6aac67c2 Mon Sep 17 00:00:00 2001 From: chagelo Date: Thu, 21 Nov 2024 17:36:20 +0800 Subject: [PATCH 2/5] * add `timezone(zone, timestamptz)` testcases Signed-off-by: chagelo --- .../regress/data/expected/timestamptz.out | 187 ++++++++++++++++++ src/tests/regress/data/sql/timestamptz.sql | 36 ++++ 2 files changed, 223 insertions(+) diff --git a/src/tests/regress/data/expected/timestamptz.out b/src/tests/regress/data/expected/timestamptz.out index 9b88cdf1916a1..29fc1c4b089ca 100644 --- a/src/tests/regress/data/expected/timestamptz.out +++ b/src/tests/regress/data/expected/timestamptz.out @@ -2636,6 +2636,193 @@ SELECT '2014-10-26 02:00:00'::timestamp AT TIME ZONE 'MSK'; 2014-10-25 23:00:00+00 (1 row) +SELECT timezone('Asia/Shanghai', '2024-11-20 20:00:00 UTC'::timestamptz); + timezone +--------------------- + 2024-11-21 04:00:00 +(1 row) + +SELECT timezone('Asia/Shanghai', '2023-02-28 20:00:00 UTC'::timestamptz); + timezone +--------------------- + 2023-03-01 04:00:00 +(1 row) + +SELECT timezone('Asia/Shanghai', '2024-02-28 20:00:00 UTC'::timestamptz); + timezone +--------------------- + 2024-02-29 04:00:00 +(1 row) + +SELECT timezone('Europe/Moscow', '2011-03-26 22:00:00 UTC'::timestamptz); + timezone +--------------------- + 2011-03-27 01:00:00 +(1 row) + +SELECT timezone('Europe/Moscow', '2011-03-26 22:59:59 UTC'::timestamptz); + timezone +--------------------- + 2011-03-27 01:59:59 +(1 row) + +SELECT timezone('Europe/Moscow', '2011-03-26 23:00:00 UTC'::timestamptz); + timezone +--------------------- + 2011-03-27 03:00:00 +(1 row) + +SELECT timezone('Europe/Moscow', '2011-03-26 23:00:01 UTC'::timestamptz); + timezone +--------------------- + 2011-03-27 03:00:01 +(1 row) + +SELECT timezone('Europe/Moscow', '2011-03-27 01:00:00 UTC'::timestamptz); + timezone +--------------------- + 2011-03-27 05:00:00 +(1 row) + +SELECT timezone('Europe/Moscow', '2011-03-27 02:00:00 UTC'::timestamptz); + timezone +--------------------- + 2011-03-27 06:00:00 +(1 row) + +SELECT timezone('Europe/Moscow', '2011-03-27 02:59:59 UTC'::timestamptz); + timezone +--------------------- + 2011-03-27 06:59:59 +(1 row) + +SELECT timezone('Europe/Moscow', '2011-03-27 03:00:00 UTC'::timestamptz); + timezone +--------------------- + 2011-03-27 07:00:00 +(1 row) + +SELECT timezone('MSK', '2011-03-26 22:00:00 UTC'::timestamptz); + timezone +--------------------- + 2011-03-27 01:00:00 +(1 row) + +SELECT timezone('MSK', '2011-03-26 22:59:59 UTC'::timestamptz); + timezone +--------------------- + 2011-03-27 01:59:59 +(1 row) + +SELECT timezone('MSK', '2011-03-26 23:00:00 UTC'::timestamptz); + timezone +--------------------- + 2011-03-27 03:00:00 +(1 row) + +SELECT timezone('MSK', '2011-03-26 23:00:01 UTC'::timestamptz); + timezone +--------------------- + 2011-03-27 03:00:01 +(1 row) + +SELECT timezone('MSK', '2011-03-27 01:00:00 UTC'::timestamptz); + timezone +--------------------- + 2011-03-27 05:00:00 +(1 row) + +SELECT timezone('MSK', '2011-03-27 02:00:00 UTC'::timestamptz); + timezone +--------------------- + 2011-03-27 06:00:00 +(1 row) + +SELECT timezone('MSK', '2011-03-27 02:59:59 UTC'::timestamptz); + timezone +--------------------- + 2011-03-27 06:59:59 +(1 row) + +SELECT timezone('MSK', '2011-03-27 03:00:00 UTC'::timestamptz); + timezone +--------------------- + 2011-03-27 07:00:00 +(1 row) + + +SELECT timezone('Europe/Moscow', '2014-10-25 21:59:59 UTC'::timestamptz); + timezone +--------------------- + 2014-10-26 01:59:59 +(1 row) + +SELECT timezone('Europe/Moscow', '2014-10-25 22:00:00 UTC'::timestamptz); + timezone +--------------------- + 2014-10-26 01:00:00 +(1 row) + +SELECT timezone('Europe/Moscow', '2014-10-25 22:59:59 UTC'::timestamptz); + timezone +--------------------- + 2014-10-26 01:59:59 +(1 row) + +SELECT timezone('Europe/Moscow', '2014-10-25 23:00:00 UTC'::timestamptz); + timezone +--------------------- + 2014-10-26 02:00:00 +(1 row) + +SELECT timezone('Europe/Moscow', '2014-10-25 23:00:01 UTC'::timestamptz); + timezone +--------------------- + 2014-10-26 02:00:01 +(1 row) + +SELECT timezone('Europe/Moscow', '2014-10-26 02:00:01 UTC'::timestamptz); + timezone +--------------------- + 2014-10-26 05:00:01 +(1 row) + +SELECT timezone('MSK', '2014-10-25 21:59:59 UTC'::timestamptz); + timezone +--------------------- + 2014-10-26 01:59:59 +(1 row) + +SELECT timezone('MSK', '2014-10-25 22:00:00 UTC'::timestamptz); + timezone +--------------------- + 2014-10-26 01:00:00 +(1 row) + +SELECT timezone('MSK', '2014-10-25 22:59:59 UTC'::timestamptz); + timezone +--------------------- + 2014-10-26 01:59:59 +(1 row) + +SELECT timezone('MSK', '2014-10-25 23:00:00 UTC'::timestamptz); + timezone +--------------------- + 2014-10-26 02:00:00 +(1 row) + +SELECT timezone('MSK', '2014-10-25 23:00:01 UTC'::timestamptz); + timezone +--------------------- + 2014-10-26 02:00:01 +(1 row) + +SELECT timezone('MSK', '2014-10-26 02:00:01 UTC'::timestamptz); + timezone +--------------------- + 2014-10-26 05:00:01 +(1 row) + SELECT make_timestamptz(2014, 10, 26, 0, 0, 0, 'MSK'); make_timestamptz ------------------------ diff --git a/src/tests/regress/data/sql/timestamptz.sql b/src/tests/regress/data/sql/timestamptz.sql index ca2877024d58d..296e5021a8494 100644 --- a/src/tests/regress/data/sql/timestamptz.sql +++ b/src/tests/regress/data/sql/timestamptz.sql @@ -480,6 +480,42 @@ SELECT '2014-10-26 01:00:00'::timestamp AT TIME ZONE 'MSK'; SELECT '2014-10-26 01:00:01'::timestamp AT TIME ZONE 'MSK'; SELECT '2014-10-26 02:00:00'::timestamp AT TIME ZONE 'MSK'; +SELECT timezone('Asia/Shanghai', '2024-11-20 20:00:00 UTC'::timestamptz); +SELECT timezone('Asia/Shanghai', '2023-02-28 20:00:00 UTC'::timestamptz); +SELECT timezone('Asia/Shanghai', '2024-02-28 20:00:00 UTC'::timestamptz); + +SELECT timezone('Europe/Moscow', '2011-03-26 22:00:00 UTC'::timestamptz); +SELECT timezone('Europe/Moscow', '2011-03-26 22:59:59 UTC'::timestamptz); +SELECT timezone('Europe/Moscow', '2011-03-26 23:00:00 UTC'::timestamptz); +SELECT timezone('Europe/Moscow', '2011-03-26 23:00:01 UTC'::timestamptz); +SELECT timezone('Europe/Moscow', '2011-03-27 01:00:00 UTC'::timestamptz); +SELECT timezone('Europe/Moscow', '2011-03-27 02:00:00 UTC'::timestamptz); +SELECT timezone('Europe/Moscow', '2011-03-27 02:59:59 UTC'::timestamptz); +SELECT timezone('Europe/Moscow', '2011-03-27 03:00:00 UTC'::timestamptz); + +SELECT timezone('MSK', '2011-03-26 22:00:00 UTC'::timestamptz); +SELECT timezone('MSK', '2011-03-26 22:59:59 UTC'::timestamptz); +SELECT timezone('MSK', '2011-03-26 23:00:00 UTC'::timestamptz); +SELECT timezone('MSK', '2011-03-26 23:00:01 UTC'::timestamptz); +SELECT timezone('MSK', '2011-03-27 01:00:00 UTC'::timestamptz); +SELECT timezone('MSK', '2011-03-27 02:00:00 UTC'::timestamptz); +SELECT timezone('MSK', '2011-03-27 02:59:59 UTC'::timestamptz); +SELECT timezone('MSK', '2011-03-27 03:00:00 UTC'::timestamptz); + +SELECT timezone('Europe/Moscow', '2014-10-25 21:59:59 UTC'::timestamptz); +SELECT timezone('Europe/Moscow', '2014-10-25 22:00:00 UTC'::timestamptz); +SELECT timezone('Europe/Moscow', '2014-10-25 22:59:59 UTC'::timestamptz); +SELECT timezone('Europe/Moscow', '2014-10-25 23:00:00 UTC'::timestamptz); +SELECT timezone('Europe/Moscow', '2014-10-25 23:00:01 UTC'::timestamptz); +SELECT timezone('Europe/Moscow', '2014-10-26 02:00:01 UTC'::timestamptz); + +SELECT timezone('MSK', '2014-10-25 21:59:59 UTC'::timestamptz); +SELECT timezone('MSK', '2014-10-25 22:00:00 UTC'::timestamptz); +SELECT timezone('MSK', '2014-10-25 22:59:59 UTC'::timestamptz); +SELECT timezone('MSK', '2014-10-25 23:00:00 UTC'::timestamptz); +SELECT timezone('MSK', '2014-10-25 23:00:01 UTC'::timestamptz); +SELECT timezone('MSK', '2014-10-26 02:00:01 UTC'::timestamptz); + SELECT make_timestamptz(2014, 10, 26, 0, 0, 0, 'MSK'); SELECT make_timestamptz(2014, 10, 26, 1, 0, 0, 'MSK'); From 6361d7ce484b6ab3da163238538c928e3d3bc232 Mon Sep 17 00:00:00 2001 From: chagelo Date: Thu, 21 Nov 2024 18:52:10 +0800 Subject: [PATCH 3/5] * add `timezone(zone, timestamp)` testcases Signed-off-by: chagelo --- src/expr/impl/src/scalar/timestamptz.rs | 5 +- .../regress/data/expected/timestamptz.out | 398 +++++++++++------- src/tests/regress/data/sql/timestamptz.sql | 80 ++-- 3 files changed, 285 insertions(+), 198 deletions(-) diff --git a/src/expr/impl/src/scalar/timestamptz.rs b/src/expr/impl/src/scalar/timestamptz.rs index 0855ef086f6b3..75a53f8a4b3c8 100644 --- a/src/expr/impl/src/scalar/timestamptz.rs +++ b/src/expr/impl/src/scalar/timestamptz.rs @@ -80,10 +80,9 @@ pub fn timestamp_at_time_zone(input: Timestamp, time_zone: &str) -> Result timestamp")] -pub fn timezone_timestamp_at_time_zone(time_zone: &str, input: Timestamp) -> Result { +#[function("timezone(varchar, timestamp) -> timestamptz")] +pub fn timezone_timestamp_at_time_zone(time_zone: &str, input: Timestamp) -> Result { timestamp_at_time_zone(input, time_zone) - .map(|timestamptz| timestamptz.to_datetime_utc().naive_utc().into()) } #[function("timezone(varchar, timestamptz) -> timestamp")] diff --git a/src/tests/regress/data/expected/timestamptz.out b/src/tests/regress/data/expected/timestamptz.out index 29fc1c4b089ca..4677335daebb4 100644 --- a/src/tests/regress/data/expected/timestamptz.out +++ b/src/tests/regress/data/expected/timestamptz.out @@ -2636,191 +2636,76 @@ SELECT '2014-10-26 02:00:00'::timestamp AT TIME ZONE 'MSK'; 2014-10-25 23:00:00+00 (1 row) -SELECT timezone('Asia/Shanghai', '2024-11-20 20:00:00 UTC'::timestamptz); - timezone ---------------------- - 2024-11-21 04:00:00 -(1 row) - -SELECT timezone('Asia/Shanghai', '2023-02-28 20:00:00 UTC'::timestamptz); - timezone ---------------------- - 2023-03-01 04:00:00 -(1 row) - -SELECT timezone('Asia/Shanghai', '2024-02-28 20:00:00 UTC'::timestamptz); - timezone ---------------------- - 2024-02-29 04:00:00 -(1 row) - -SELECT timezone('Europe/Moscow', '2011-03-26 22:00:00 UTC'::timestamptz); - timezone ---------------------- - 2011-03-27 01:00:00 -(1 row) - -SELECT timezone('Europe/Moscow', '2011-03-26 22:59:59 UTC'::timestamptz); - timezone ---------------------- - 2011-03-27 01:59:59 -(1 row) - -SELECT timezone('Europe/Moscow', '2011-03-26 23:00:00 UTC'::timestamptz); - timezone ---------------------- - 2011-03-27 03:00:00 -(1 row) - -SELECT timezone('Europe/Moscow', '2011-03-26 23:00:01 UTC'::timestamptz); - timezone ---------------------- - 2011-03-27 03:00:01 -(1 row) - -SELECT timezone('Europe/Moscow', '2011-03-27 01:00:00 UTC'::timestamptz); - timezone ---------------------- - 2011-03-27 05:00:00 -(1 row) - -SELECT timezone('Europe/Moscow', '2011-03-27 02:00:00 UTC'::timestamptz); - timezone ---------------------- - 2011-03-27 06:00:00 -(1 row) - -SELECT timezone('Europe/Moscow', '2011-03-27 02:59:59 UTC'::timestamptz); - timezone ---------------------- - 2011-03-27 06:59:59 -(1 row) - -SELECT timezone('Europe/Moscow', '2011-03-27 03:00:00 UTC'::timestamptz); - timezone ---------------------- - 2011-03-27 07:00:00 -(1 row) - -SELECT timezone('MSK', '2011-03-26 22:00:00 UTC'::timestamptz); - timezone ---------------------- - 2011-03-27 01:00:00 -(1 row) - -SELECT timezone('MSK', '2011-03-26 22:59:59 UTC'::timestamptz); - timezone ---------------------- - 2011-03-27 01:59:59 -(1 row) - -SELECT timezone('MSK', '2011-03-26 23:00:00 UTC'::timestamptz); - timezone ---------------------- - 2011-03-27 03:00:00 -(1 row) - -SELECT timezone('MSK', '2011-03-26 23:00:01 UTC'::timestamptz); - timezone ---------------------- - 2011-03-27 03:00:01 -(1 row) - -SELECT timezone('MSK', '2011-03-27 01:00:00 UTC'::timestamptz); - timezone ---------------------- - 2011-03-27 05:00:00 -(1 row) - -SELECT timezone('MSK', '2011-03-27 02:00:00 UTC'::timestamptz); - timezone ---------------------- - 2011-03-27 06:00:00 -(1 row) - -SELECT timezone('MSK', '2011-03-27 02:59:59 UTC'::timestamptz); - timezone ---------------------- - 2011-03-27 06:59:59 -(1 row) - -SELECT timezone('MSK', '2011-03-27 03:00:00 UTC'::timestamptz); - timezone ---------------------- - 2011-03-27 07:00:00 -(1 row) - - -SELECT timezone('Europe/Moscow', '2014-10-25 21:59:59 UTC'::timestamptz); - timezone ---------------------- - 2014-10-26 01:59:59 +SELECT timezone('Europe/Moscow', '2011-03-27 02:00:00'::timestamp); + timezone +--------------------------- + 2011-03-26 23:00:00+00 (1 row) -SELECT timezone('Europe/Moscow', '2014-10-25 22:00:00 UTC'::timestamptz); - timezone ---------------------- - 2014-10-26 01:00:00 +SELECT timezone('Europe/Moscow', '2011-03-27 02:59:59'::timestamp); + timezone +--------------------------- + 2011-03-26 23:59:59+00 (1 row) -SELECT timezone('Europe/Moscow', '2014-10-25 22:59:59 UTC'::timestamptz); - timezone ---------------------- - 2014-10-26 01:59:59 +SELECT timezone('Europe/Moscow', '2011-03-27 03:00:00'::timestamp); + timezone +--------------------------- + 2011-03-26 23:00:00+00 (1 row) -SELECT timezone('Europe/Moscow', '2014-10-25 23:00:00 UTC'::timestamptz); - timezone ---------------------- - 2014-10-26 02:00:00 +SELECT timezone('MSK', '2011-03-27 02:00:00'::timestamp); + timezone +------------------------ + 2011-03-26 22:00:00+00 (1 row) -SELECT timezone('Europe/Moscow', '2014-10-25 23:00:01 UTC'::timestamptz); - timezone ---------------------- - 2014-10-26 02:00:01 +SELECT timezone('MSK', '2011-03-27 02:59:59'::timestamp); + timezone +------------------------ + 2011-03-26 22:59:59+00 (1 row) -SELECT timezone('Europe/Moscow', '2014-10-26 02:00:01 UTC'::timestamptz); - timezone ---------------------- - 2014-10-26 05:00:01 +SELECT timezone('MSK', '2011-03-27 03:00:00'::timestamp); + timezone +------------------------ + 2011-03-26 23:00:00+00 (1 row) -SELECT timezone('MSK', '2014-10-25 21:59:59 UTC'::timestamptz); - timezone ---------------------- - 2014-10-26 01:59:59 +SELECT timezone('Europe/Moscow', '2014-10-26 00:59:59'::timestamp); + timezone +--------------------------- + 2014-10-25 20:59:59+00 (1 row) -SELECT timezone('MSK', '2014-10-25 22:00:00 UTC'::timestamptz); - timezone ---------------------- - 2014-10-26 01:00:00 +SELECT timezone('Europe/Moscow', '2014-10-26 01:00:00'::timestamp); + timezone +--------------------------- + 2014-10-25 22:00:00+00 (1 row) -SELECT timezone('MSK', '2014-10-25 22:59:59 UTC'::timestamptz); - timezone ---------------------- - 2014-10-26 01:59:59 +SELECT timezone('Europe/Moscow', '2014-10-26 01:00:01'::timestamp); + timezone +--------------------------- + 2014-10-25 22:00:01+00 (1 row) -SELECT timezone('MSK', '2014-10-25 23:00:00 UTC'::timestamptz); - timezone ---------------------- - 2014-10-26 02:00:00 +SELECT timezone('MSK', '2014-10-26 00:59:59'::timestamp); + timezone +------------------------ + 2014-10-25 20:59:59+00 (1 row) -SELECT timezone('MSK', '2014-10-25 23:00:01 UTC'::timestamptz); - timezone ---------------------- - 2014-10-26 02:00:01 +SELECT timezone('MSK', '2014-10-26 01:00:00'::timestamp); + timezone +------------------------ + 2014-10-25 22:00:00+00 (1 row) -SELECT timezone('MSK', '2014-10-26 02:00:01 UTC'::timestamptz); - timezone ---------------------- - 2014-10-26 05:00:01 +SELECT timezone('MSK', '2014-10-26 01:00:01'::timestamp); + timezone +------------------------ + 2014-10-25 22:00:01+00 (1 row) SELECT make_timestamptz(2014, 10, 26, 0, 0, 0, 'MSK'); @@ -3094,6 +2979,193 @@ SELECT '2014-10-25 23:00:00 UTC'::timestamptz AT TIME ZONE 'MSK'; 2014-10-26 02:00:00 (1 row) +SELECT timezone('Asia/Shanghai', '2024-11-20 20:00:00 UTC'::timestamptz); + timezone +--------------------- + 2024-11-21 04:00:00 +(1 row) + +SELECT timezone('Asia/Shanghai', '2023-02-28 20:00:00 UTC'::timestamptz); + timezone +--------------------- + 2023-03-01 04:00:00 +(1 row) + +SELECT timezone('Asia/Shanghai', '2024-02-28 20:00:00 UTC'::timestamptz); + timezone +--------------------- + 2024-02-29 04:00:00 +(1 row) + +SELECT timezone('Europe/Moscow', '2011-03-26 22:00:00 UTC'::timestamptz); + timezone +--------------------- + 2011-03-27 01:00:00 +(1 row) + +SELECT timezone('Europe/Moscow', '2011-03-26 22:59:59 UTC'::timestamptz); + timezone +--------------------- + 2011-03-27 01:59:59 +(1 row) + +SELECT timezone('Europe/Moscow', '2011-03-26 23:00:00 UTC'::timestamptz); + timezone +--------------------- + 2011-03-27 03:00:00 +(1 row) + +SELECT timezone('Europe/Moscow', '2011-03-26 23:00:01 UTC'::timestamptz); + timezone +--------------------- + 2011-03-27 03:00:01 +(1 row) + +SELECT timezone('Europe/Moscow', '2011-03-27 01:00:00 UTC'::timestamptz); + timezone +--------------------- + 2011-03-27 05:00:00 +(1 row) + +SELECT timezone('Europe/Moscow', '2011-03-27 02:00:00 UTC'::timestamptz); + timezone +--------------------- + 2011-03-27 06:00:00 +(1 row) + +SELECT timezone('Europe/Moscow', '2011-03-27 02:59:59 UTC'::timestamptz); + timezone +--------------------- + 2011-03-27 06:59:59 +(1 row) + +SELECT timezone('Europe/Moscow', '2011-03-27 03:00:00 UTC'::timestamptz); + timezone +--------------------- + 2011-03-27 07:00:00 +(1 row) + +SELECT timezone('MSK', '2011-03-26 22:00:00 UTC'::timestamptz); + timezone +--------------------- + 2011-03-27 01:00:00 +(1 row) + +SELECT timezone('MSK', '2011-03-26 22:59:59 UTC'::timestamptz); + timezone +--------------------- + 2011-03-27 01:59:59 +(1 row) + +SELECT timezone('MSK', '2011-03-26 23:00:00 UTC'::timestamptz); + timezone +--------------------- + 2011-03-27 03:00:00 +(1 row) + +SELECT timezone('MSK', '2011-03-26 23:00:01 UTC'::timestamptz); + timezone +--------------------- + 2011-03-27 03:00:01 +(1 row) + +SELECT timezone('MSK', '2011-03-27 01:00:00 UTC'::timestamptz); + timezone +--------------------- + 2011-03-27 05:00:00 +(1 row) + +SELECT timezone('MSK', '2011-03-27 02:00:00 UTC'::timestamptz); + timezone +--------------------- + 2011-03-27 06:00:00 +(1 row) + +SELECT timezone('MSK', '2011-03-27 02:59:59 UTC'::timestamptz); + timezone +--------------------- + 2011-03-27 06:59:59 +(1 row) + +SELECT timezone('MSK', '2011-03-27 03:00:00 UTC'::timestamptz); + timezone +--------------------- + 2011-03-27 07:00:00 +(1 row) + + +SELECT timezone('Europe/Moscow', '2014-10-25 21:59:59 UTC'::timestamptz); + timezone +--------------------- + 2014-10-26 01:59:59 +(1 row) + +SELECT timezone('Europe/Moscow', '2014-10-25 22:00:00 UTC'::timestamptz); + timezone +--------------------- + 2014-10-26 01:00:00 +(1 row) + +SELECT timezone('Europe/Moscow', '2014-10-25 22:59:59 UTC'::timestamptz); + timezone +--------------------- + 2014-10-26 01:59:59 +(1 row) + +SELECT timezone('Europe/Moscow', '2014-10-25 23:00:00 UTC'::timestamptz); + timezone +--------------------- + 2014-10-26 02:00:00 +(1 row) + +SELECT timezone('Europe/Moscow', '2014-10-25 23:00:01 UTC'::timestamptz); + timezone +--------------------- + 2014-10-26 02:00:01 +(1 row) + +SELECT timezone('Europe/Moscow', '2014-10-26 02:00:01 UTC'::timestamptz); + timezone +--------------------- + 2014-10-26 05:00:01 +(1 row) + +SELECT timezone('MSK', '2014-10-25 21:59:59 UTC'::timestamptz); + timezone +--------------------- + 2014-10-26 01:59:59 +(1 row) + +SELECT timezone('MSK', '2014-10-25 22:00:00 UTC'::timestamptz); + timezone +--------------------- + 2014-10-26 01:00:00 +(1 row) + +SELECT timezone('MSK', '2014-10-25 22:59:59 UTC'::timestamptz); + timezone +--------------------- + 2014-10-26 01:59:59 +(1 row) + +SELECT timezone('MSK', '2014-10-25 23:00:00 UTC'::timestamptz); + timezone +--------------------- + 2014-10-26 02:00:00 +(1 row) + +SELECT timezone('MSK', '2014-10-25 23:00:01 UTC'::timestamptz); + timezone +--------------------- + 2014-10-26 02:00:01 +(1 row) + +SELECT timezone('MSK', '2014-10-26 02:00:01 UTC'::timestamptz); + timezone +--------------------- + 2014-10-26 05:00:01 +(1 row) + -- -- Test that AT TIME ZONE isn't misoptimized when using an index (bug #14504) -- diff --git a/src/tests/regress/data/sql/timestamptz.sql b/src/tests/regress/data/sql/timestamptz.sql index 296e5021a8494..c1b34a3503a16 100644 --- a/src/tests/regress/data/sql/timestamptz.sql +++ b/src/tests/regress/data/sql/timestamptz.sql @@ -480,41 +480,21 @@ SELECT '2014-10-26 01:00:00'::timestamp AT TIME ZONE 'MSK'; SELECT '2014-10-26 01:00:01'::timestamp AT TIME ZONE 'MSK'; SELECT '2014-10-26 02:00:00'::timestamp AT TIME ZONE 'MSK'; -SELECT timezone('Asia/Shanghai', '2024-11-20 20:00:00 UTC'::timestamptz); -SELECT timezone('Asia/Shanghai', '2023-02-28 20:00:00 UTC'::timestamptz); -SELECT timezone('Asia/Shanghai', '2024-02-28 20:00:00 UTC'::timestamptz); +SELECT timezone('Europe/Moscow', '2011-03-27 02:00:00'::timestamp); +SELECT timezone('Europe/Moscow', '2011-03-27 02:59:59'::timestamp); +SELECT timezone('Europe/Moscow', '2011-03-27 03:00:00'::timestamp); -SELECT timezone('Europe/Moscow', '2011-03-26 22:00:00 UTC'::timestamptz); -SELECT timezone('Europe/Moscow', '2011-03-26 22:59:59 UTC'::timestamptz); -SELECT timezone('Europe/Moscow', '2011-03-26 23:00:00 UTC'::timestamptz); -SELECT timezone('Europe/Moscow', '2011-03-26 23:00:01 UTC'::timestamptz); -SELECT timezone('Europe/Moscow', '2011-03-27 01:00:00 UTC'::timestamptz); -SELECT timezone('Europe/Moscow', '2011-03-27 02:00:00 UTC'::timestamptz); -SELECT timezone('Europe/Moscow', '2011-03-27 02:59:59 UTC'::timestamptz); -SELECT timezone('Europe/Moscow', '2011-03-27 03:00:00 UTC'::timestamptz); - -SELECT timezone('MSK', '2011-03-26 22:00:00 UTC'::timestamptz); -SELECT timezone('MSK', '2011-03-26 22:59:59 UTC'::timestamptz); -SELECT timezone('MSK', '2011-03-26 23:00:00 UTC'::timestamptz); -SELECT timezone('MSK', '2011-03-26 23:00:01 UTC'::timestamptz); -SELECT timezone('MSK', '2011-03-27 01:00:00 UTC'::timestamptz); -SELECT timezone('MSK', '2011-03-27 02:00:00 UTC'::timestamptz); -SELECT timezone('MSK', '2011-03-27 02:59:59 UTC'::timestamptz); -SELECT timezone('MSK', '2011-03-27 03:00:00 UTC'::timestamptz); +SELECT timezone('MSK', '2011-03-27 02:00:00'::timestamp); +SELECT timezone('MSK', '2011-03-27 02:59:59'::timestamp); +SELECT timezone('MSK', '2011-03-27 03:00:00'::timestamp); -SELECT timezone('Europe/Moscow', '2014-10-25 21:59:59 UTC'::timestamptz); -SELECT timezone('Europe/Moscow', '2014-10-25 22:00:00 UTC'::timestamptz); -SELECT timezone('Europe/Moscow', '2014-10-25 22:59:59 UTC'::timestamptz); -SELECT timezone('Europe/Moscow', '2014-10-25 23:00:00 UTC'::timestamptz); -SELECT timezone('Europe/Moscow', '2014-10-25 23:00:01 UTC'::timestamptz); -SELECT timezone('Europe/Moscow', '2014-10-26 02:00:01 UTC'::timestamptz); +SELECT timezone('Europe/Moscow', '2014-10-26 00:59:59'::timestamp); +SELECT timezone('Europe/Moscow', '2014-10-26 01:00:00'::timestamp); +SELECT timezone('Europe/Moscow', '2014-10-26 01:00:01'::timestamp); -SELECT timezone('MSK', '2014-10-25 21:59:59 UTC'::timestamptz); -SELECT timezone('MSK', '2014-10-25 22:00:00 UTC'::timestamptz); -SELECT timezone('MSK', '2014-10-25 22:59:59 UTC'::timestamptz); -SELECT timezone('MSK', '2014-10-25 23:00:00 UTC'::timestamptz); -SELECT timezone('MSK', '2014-10-25 23:00:01 UTC'::timestamptz); -SELECT timezone('MSK', '2014-10-26 02:00:01 UTC'::timestamptz); +SELECT timezone('MSK', '2014-10-26 00:59:59'::timestamp); +SELECT timezone('MSK', '2014-10-26 01:00:00'::timestamp); +SELECT timezone('MSK', '2014-10-26 01:00:01'::timestamp); SELECT make_timestamptz(2014, 10, 26, 0, 0, 0, 'MSK'); SELECT make_timestamptz(2014, 10, 26, 1, 0, 0, 'MSK'); @@ -577,6 +557,42 @@ SELECT '2014-10-25 22:00:00 UTC'::timestamptz AT TIME ZONE 'MSK'; SELECT '2014-10-25 22:00:01 UTC'::timestamptz AT TIME ZONE 'MSK'; SELECT '2014-10-25 23:00:00 UTC'::timestamptz AT TIME ZONE 'MSK'; +SELECT timezone('Asia/Shanghai', '2024-11-20 20:00:00 UTC'::timestamptz); +SELECT timezone('Asia/Shanghai', '2023-02-28 20:00:00 UTC'::timestamptz); +SELECT timezone('Asia/Shanghai', '2024-02-28 20:00:00 UTC'::timestamptz); + +SELECT timezone('Europe/Moscow', '2011-03-26 22:00:00 UTC'::timestamptz); +SELECT timezone('Europe/Moscow', '2011-03-26 22:59:59 UTC'::timestamptz); +SELECT timezone('Europe/Moscow', '2011-03-26 23:00:00 UTC'::timestamptz); +SELECT timezone('Europe/Moscow', '2011-03-26 23:00:01 UTC'::timestamptz); +SELECT timezone('Europe/Moscow', '2011-03-27 01:00:00 UTC'::timestamptz); +SELECT timezone('Europe/Moscow', '2011-03-27 02:00:00 UTC'::timestamptz); +SELECT timezone('Europe/Moscow', '2011-03-27 02:59:59 UTC'::timestamptz); +SELECT timezone('Europe/Moscow', '2011-03-27 03:00:00 UTC'::timestamptz); + +SELECT timezone('MSK', '2011-03-26 22:00:00 UTC'::timestamptz); +SELECT timezone('MSK', '2011-03-26 22:59:59 UTC'::timestamptz); +SELECT timezone('MSK', '2011-03-26 23:00:00 UTC'::timestamptz); +SELECT timezone('MSK', '2011-03-26 23:00:01 UTC'::timestamptz); +SELECT timezone('MSK', '2011-03-27 01:00:00 UTC'::timestamptz); +SELECT timezone('MSK', '2011-03-27 02:00:00 UTC'::timestamptz); +SELECT timezone('MSK', '2011-03-27 02:59:59 UTC'::timestamptz); +SELECT timezone('MSK', '2011-03-27 03:00:00 UTC'::timestamptz); + +SELECT timezone('Europe/Moscow', '2014-10-25 21:59:59 UTC'::timestamptz); +SELECT timezone('Europe/Moscow', '2014-10-25 22:00:00 UTC'::timestamptz); +SELECT timezone('Europe/Moscow', '2014-10-25 22:59:59 UTC'::timestamptz); +SELECT timezone('Europe/Moscow', '2014-10-25 23:00:00 UTC'::timestamptz); +SELECT timezone('Europe/Moscow', '2014-10-25 23:00:01 UTC'::timestamptz); +SELECT timezone('Europe/Moscow', '2014-10-26 02:00:01 UTC'::timestamptz); + +SELECT timezone('MSK', '2014-10-25 21:59:59 UTC'::timestamptz); +SELECT timezone('MSK', '2014-10-25 22:00:00 UTC'::timestamptz); +SELECT timezone('MSK', '2014-10-25 22:59:59 UTC'::timestamptz); +SELECT timezone('MSK', '2014-10-25 23:00:00 UTC'::timestamptz); +SELECT timezone('MSK', '2014-10-25 23:00:01 UTC'::timestamptz); +SELECT timezone('MSK', '2014-10-26 02:00:01 UTC'::timestamptz); + -- -- Test that AT TIME ZONE isn't misoptimized when using an index (bug #14504) -- From bea8d672b074c9fb1cdca3926a20db4b355b0638 Mon Sep 17 00:00:00 2001 From: chagelo Date: Fri, 22 Nov 2024 16:24:08 +0800 Subject: [PATCH 4/5] fix Signed-off-by: chagelo --- .../batch/functions/at_time_zone.slt.part | 11 + proto/expr.proto | 1 - src/expr/impl/src/scalar/timestamptz.rs | 16 - .../binder/expr/function/builtin_scalar.rs | 9 +- src/frontend/src/expr/pure.rs | 1 - .../src/optimizer/plan_expr_visitor/strong.rs | 1 - .../regress/data/expected/timestamptz.out | 342 +++++++++--------- src/tests/regress/data/schedule | 13 +- 8 files changed, 196 insertions(+), 198 deletions(-) diff --git a/e2e_test/batch/functions/at_time_zone.slt.part b/e2e_test/batch/functions/at_time_zone.slt.part index cfd89b3312965..75a1e3a5d67ca 100644 --- a/e2e_test/batch/functions/at_time_zone.slt.part +++ b/e2e_test/batch/functions/at_time_zone.slt.part @@ -37,3 +37,14 @@ select local AT TIME ZONE tz from t order by 1; statement ok drop table t; + +# timezone function +query T +select timezone('Europe/Moscow', '2014-10-25 22:00:00 UTC'::timestamptz); +---- +2014-10-26 01:00:00 + +query T +select timezone('Europe/Moscow', '2011-03-26 23:00:00 UTC'::timestamptz); +---- +2011-03-27 03:00:00 \ No newline at end of file diff --git a/proto/expr.proto b/proto/expr.proto index a91d0ac173c2f..e56668c990447 100644 --- a/proto/expr.proto +++ b/proto/expr.proto @@ -70,7 +70,6 @@ message ExprNode { ADD_WITH_TIME_ZONE = 109; SUBTRACT_WITH_TIME_ZONE = 110; MAKE_TIMESTAMPTZ = 112; - Timezone = 116; // other functions CAST = 201; SUBSTR = 202; diff --git a/src/expr/impl/src/scalar/timestamptz.rs b/src/expr/impl/src/scalar/timestamptz.rs index 75a53f8a4b3c8..06f9f2a7ffba4 100644 --- a/src/expr/impl/src/scalar/timestamptz.rs +++ b/src/expr/impl/src/scalar/timestamptz.rs @@ -80,16 +80,6 @@ pub fn timestamp_at_time_zone(input: Timestamp, time_zone: &str) -> Result timestamptz")] -pub fn timezone_timestamp_at_time_zone(time_zone: &str, input: Timestamp) -> Result { - timestamp_at_time_zone(input, time_zone) -} - -#[function("timezone(varchar, timestamptz) -> timestamp")] -pub fn timezone_timestamptz_at_time_zone(time_zone: &str, input: Timestamptz) -> Result { - timestamptz_at_time_zone(input, time_zone) -} - #[function("cast_with_time_zone(timestamptz, varchar) -> varchar")] pub fn timestamptz_to_string( elem: Timestamptz, @@ -238,12 +228,6 @@ mod tests { .for_each(|(local, zone)| { let local = local.parse().unwrap(); - let actual = timezone_timestamptz_at_time_zone(zone, usecs).unwrap(); - assert_eq!(local, actual); - - let actual = timezone_timestamp_at_time_zone(zone, local).unwrap(); - assert_eq!(Timestamp::from(usecs.to_datetime_utc().naive_utc()), actual); - let actual = timestamptz_at_time_zone(usecs, zone).unwrap(); assert_eq!(local, actual); diff --git a/src/frontend/src/binder/expr/function/builtin_scalar.rs b/src/frontend/src/binder/expr/function/builtin_scalar.rs index 61892829dbf69..7570f72c5d095 100644 --- a/src/frontend/src/binder/expr/function/builtin_scalar.rs +++ b/src/frontend/src/binder/expr/function/builtin_scalar.rs @@ -224,7 +224,14 @@ impl Binder { ("make_time", raw_call(ExprType::MakeTime)), ("make_timestamp", raw_call(ExprType::MakeTimestamp)), ("make_timestamptz", raw_call(ExprType::MakeTimestamptz)), - ("timezone", raw_call(ExprType::Timezone)), + ("timezone", rewrite(ExprType::AtTimeZone, |mut inputs|{ + if inputs.len() == 2 { + inputs.swap(0, 1); + Ok(inputs) + } else { + Err(ErrorCode::ExprError("unexpected arguments number".into()).into()) + } + })), ("to_date", raw_call(ExprType::CharToDate)), // string ("substr", raw_call(ExprType::Substr)), diff --git a/src/frontend/src/expr/pure.rs b/src/frontend/src/expr/pure.rs index a70efbe91a79f..83a8cfa537bae 100644 --- a/src/frontend/src/expr/pure.rs +++ b/src/frontend/src/expr/pure.rs @@ -72,7 +72,6 @@ impl ExprVisitor for ImpureAnalyzer { | Type::CastWithTimeZone | Type::AddWithTimeZone | Type::SubtractWithTimeZone - | Type::Timezone | Type::Cast | Type::Substr | Type::Length diff --git a/src/frontend/src/optimizer/plan_expr_visitor/strong.rs b/src/frontend/src/optimizer/plan_expr_visitor/strong.rs index e99a3260497c8..c53bde642ad3e 100644 --- a/src/frontend/src/optimizer/plan_expr_visitor/strong.rs +++ b/src/frontend/src/optimizer/plan_expr_visitor/strong.rs @@ -135,7 +135,6 @@ impl Strong { | ExprType::CastWithTimeZone | ExprType::SubtractWithTimeZone | ExprType::MakeTimestamptz - | ExprType::Timezone | ExprType::Substr | ExprType::Length | ExprType::ILike diff --git a/src/tests/regress/data/expected/timestamptz.out b/src/tests/regress/data/expected/timestamptz.out index 4677335daebb4..2512514fc1ceb 100644 --- a/src/tests/regress/data/expected/timestamptz.out +++ b/src/tests/regress/data/expected/timestamptz.out @@ -2469,249 +2469,249 @@ SELECT '2014-10-26 02:00:00 MSK'::timestamptz; (1 row) SELECT '2011-03-27 00:00:00'::timestamp AT TIME ZONE 'Europe/Moscow'; - timezone ------------------------- - 2011-03-26 21:00:00+00 + ?column? +--------------------------- + 2011-03-26 21:00:00+00:00 (1 row) SELECT '2011-03-27 01:00:00'::timestamp AT TIME ZONE 'Europe/Moscow'; - timezone ------------------------- - 2011-03-26 22:00:00+00 + ?column? +--------------------------- + 2011-03-26 22:00:00+00:00 (1 row) SELECT '2011-03-27 01:59:59'::timestamp AT TIME ZONE 'Europe/Moscow'; - timezone ------------------------- - 2011-03-26 22:59:59+00 + ?column? +--------------------------- + 2011-03-26 22:59:59+00:00 (1 row) SELECT '2011-03-27 02:00:00'::timestamp AT TIME ZONE 'Europe/Moscow'; - timezone ------------------------- - 2011-03-26 23:00:00+00 + ?column? +--------------------------- + 2011-03-26 23:00:00+00:00 (1 row) SELECT '2011-03-27 02:00:01'::timestamp AT TIME ZONE 'Europe/Moscow'; - timezone ------------------------- - 2011-03-26 23:00:01+00 + ?column? +--------------------------- + 2011-03-26 23:00:01+00:00 (1 row) SELECT '2011-03-27 02:59:59'::timestamp AT TIME ZONE 'Europe/Moscow'; - timezone ------------------------- - 2011-03-26 23:59:59+00 + ?column? +--------------------------- + 2011-03-26 23:59:59+00:00 (1 row) SELECT '2011-03-27 03:00:00'::timestamp AT TIME ZONE 'Europe/Moscow'; - timezone ------------------------- - 2011-03-26 23:00:00+00 + ?column? +--------------------------- + 2011-03-26 23:00:00+00:00 (1 row) SELECT '2011-03-27 03:00:01'::timestamp AT TIME ZONE 'Europe/Moscow'; - timezone ------------------------- - 2011-03-26 23:00:01+00 + ?column? +--------------------------- + 2011-03-26 23:00:01+00:00 (1 row) SELECT '2011-03-27 04:00:00'::timestamp AT TIME ZONE 'Europe/Moscow'; - timezone ------------------------- - 2011-03-27 00:00:00+00 + ?column? +--------------------------- + 2011-03-27 00:00:00+00:00 (1 row) SELECT '2011-03-27 00:00:00'::timestamp AT TIME ZONE 'MSK'; - timezone ------------------------- - 2011-03-26 21:00:00+00 + ?column? +--------------------------- + 2011-03-26 21:00:00+00:00 (1 row) SELECT '2011-03-27 01:00:00'::timestamp AT TIME ZONE 'MSK'; - timezone ------------------------- - 2011-03-26 22:00:00+00 + ?column? +--------------------------- + 2011-03-26 22:00:00+00:00 (1 row) SELECT '2011-03-27 01:59:59'::timestamp AT TIME ZONE 'MSK'; - timezone ------------------------- - 2011-03-26 22:59:59+00 + ?column? +--------------------------- + 2011-03-26 22:59:59+00:00 (1 row) SELECT '2011-03-27 02:00:00'::timestamp AT TIME ZONE 'MSK'; - timezone ------------------------- - 2011-03-26 22:00:00+00 + ?column? +--------------------------- + 2011-03-26 22:00:00+00:00 (1 row) SELECT '2011-03-27 02:00:01'::timestamp AT TIME ZONE 'MSK'; - timezone ------------------------- - 2011-03-26 22:00:01+00 + ?column? +--------------------------- + 2011-03-26 22:00:01+00:00 (1 row) SELECT '2011-03-27 02:59:59'::timestamp AT TIME ZONE 'MSK'; - timezone ------------------------- - 2011-03-26 22:59:59+00 + ?column? +--------------------------- + 2011-03-26 22:59:59+00:00 (1 row) SELECT '2011-03-27 03:00:00'::timestamp AT TIME ZONE 'MSK'; - timezone ------------------------- - 2011-03-26 23:00:00+00 + ?column? +--------------------------- + 2011-03-26 23:00:00+00:00 (1 row) SELECT '2011-03-27 03:00:01'::timestamp AT TIME ZONE 'MSK'; - timezone ------------------------- - 2011-03-26 23:00:01+00 + ?column? +--------------------------- + 2011-03-26 23:00:01+00:00 (1 row) SELECT '2011-03-27 04:00:00'::timestamp AT TIME ZONE 'MSK'; - timezone ------------------------- - 2011-03-27 00:00:00+00 + ?column? +--------------------------- + 2011-03-27 00:00:00+00:00 (1 row) SELECT '2014-10-26 00:00:00'::timestamp AT TIME ZONE 'Europe/Moscow'; - timezone ------------------------- - 2014-10-25 20:00:00+00 + ?column? +--------------------------- + 2014-10-25 20:00:00+00:00 (1 row) SELECT '2014-10-26 00:59:59'::timestamp AT TIME ZONE 'Europe/Moscow'; - timezone ------------------------- - 2014-10-25 20:59:59+00 + ?column? +--------------------------- + 2014-10-25 20:59:59+00:00 (1 row) SELECT '2014-10-26 01:00:00'::timestamp AT TIME ZONE 'Europe/Moscow'; - timezone ------------------------- - 2014-10-25 22:00:00+00 + ?column? +--------------------------- + 2014-10-25 22:00:00+00:00 (1 row) SELECT '2014-10-26 01:00:01'::timestamp AT TIME ZONE 'Europe/Moscow'; - timezone ------------------------- - 2014-10-25 22:00:01+00 + ?column? +--------------------------- + 2014-10-25 22:00:01+00:00 (1 row) SELECT '2014-10-26 02:00:00'::timestamp AT TIME ZONE 'Europe/Moscow'; - timezone ------------------------- - 2014-10-25 23:00:00+00 + ?column? +--------------------------- + 2014-10-25 23:00:00+00:00 (1 row) SELECT '2014-10-26 00:00:00'::timestamp AT TIME ZONE 'MSK'; - timezone ------------------------- - 2014-10-25 20:00:00+00 + ?column? +--------------------------- + 2014-10-25 20:00:00+00:00 (1 row) SELECT '2014-10-26 00:59:59'::timestamp AT TIME ZONE 'MSK'; - timezone ------------------------- - 2014-10-25 20:59:59+00 + ?column? +--------------------------- + 2014-10-25 20:59:59+00:00 (1 row) SELECT '2014-10-26 01:00:00'::timestamp AT TIME ZONE 'MSK'; - timezone ------------------------- - 2014-10-25 22:00:00+00 + ?column? +--------------------------- + 2014-10-25 22:00:00+00:00 (1 row) SELECT '2014-10-26 01:00:01'::timestamp AT TIME ZONE 'MSK'; - timezone ------------------------- - 2014-10-25 22:00:01+00 + ?column? +--------------------------- + 2014-10-25 22:00:01+00:00 (1 row) SELECT '2014-10-26 02:00:00'::timestamp AT TIME ZONE 'MSK'; - timezone ------------------------- - 2014-10-25 23:00:00+00 + ?column? +--------------------------- + 2014-10-25 23:00:00+00:00 (1 row) SELECT timezone('Europe/Moscow', '2011-03-27 02:00:00'::timestamp); timezone --------------------------- - 2011-03-26 23:00:00+00 + 2011-03-26 23:00:00+00:00 (1 row) SELECT timezone('Europe/Moscow', '2011-03-27 02:59:59'::timestamp); timezone --------------------------- - 2011-03-26 23:59:59+00 + 2011-03-26 23:59:59+00:00 (1 row) SELECT timezone('Europe/Moscow', '2011-03-27 03:00:00'::timestamp); timezone --------------------------- - 2011-03-26 23:00:00+00 + 2011-03-26 23:00:00+00:00 (1 row) SELECT timezone('MSK', '2011-03-27 02:00:00'::timestamp); - timezone ------------------------- - 2011-03-26 22:00:00+00 + timezone +--------------------------- + 2011-03-26 22:00:00+00:00 (1 row) SELECT timezone('MSK', '2011-03-27 02:59:59'::timestamp); - timezone ------------------------- - 2011-03-26 22:59:59+00 + timezone +--------------------------- + 2011-03-26 22:59:59+00:00 (1 row) SELECT timezone('MSK', '2011-03-27 03:00:00'::timestamp); - timezone ------------------------- - 2011-03-26 23:00:00+00 + timezone +--------------------------- + 2011-03-26 23:00:00+00:00 (1 row) SELECT timezone('Europe/Moscow', '2014-10-26 00:59:59'::timestamp); timezone --------------------------- - 2014-10-25 20:59:59+00 + 2014-10-25 20:59:59+00:00 (1 row) SELECT timezone('Europe/Moscow', '2014-10-26 01:00:00'::timestamp); timezone --------------------------- - 2014-10-25 22:00:00+00 + 2014-10-25 22:00:00+00:00 (1 row) SELECT timezone('Europe/Moscow', '2014-10-26 01:00:01'::timestamp); timezone --------------------------- - 2014-10-25 22:00:01+00 + 2014-10-25 22:00:01+00:00 (1 row) SELECT timezone('MSK', '2014-10-26 00:59:59'::timestamp); - timezone ------------------------- - 2014-10-25 20:59:59+00 + timezone +--------------------------- + 2014-10-25 20:59:59+00:00 (1 row) SELECT timezone('MSK', '2014-10-26 01:00:00'::timestamp); - timezone ------------------------- - 2014-10-25 22:00:00+00 + timezone +--------------------------- + 2014-10-25 22:00:00+00:00 (1 row) SELECT timezone('MSK', '2014-10-26 01:00:01'::timestamp); - timezone ------------------------- - 2014-10-25 22:00:01+00 + timezone +--------------------------- + 2014-10-25 22:00:01+00:00 (1 row) SELECT make_timestamptz(2014, 10, 26, 0, 0, 0, 'MSK'); - make_timestamptz ------------------------- - 2014-10-25 20:00:00+00 + make_timestamptz +--------------------------- + 2014-10-25 20:00:00+00:00 (1 row) SELECT make_timestamptz(2014, 10, 26, 1, 0, 0, 'MSK'); @@ -2721,28 +2721,28 @@ SELECT make_timestamptz(2014, 10, 26, 1, 0, 0, 'MSK'); (1 row) SELECT to_timestamp( 0); -- 1970-01-01 00:00:00+00 - to_timestamp ------------------------- - 1970-01-01 00:00:00+00 + to_timestamp +--------------------------- + 1970-01-01 00:00:00+00:00 (1 row) SELECT to_timestamp( 946684800); -- 2000-01-01 00:00:00+00 - to_timestamp ------------------------- - 2000-01-01 00:00:00+00 + to_timestamp +--------------------------- + 2000-01-01 00:00:00+00:00 (1 row) SELECT to_timestamp(1262349296.7890123); -- 2010-01-01 12:34:56.789012+00 - to_timestamp -------------------------------- - 2010-01-01 12:34:56.789012+00 + to_timestamp +---------------------------------- + 2010-01-01 12:34:56.789012+00:00 (1 row) -- edge cases SELECT to_timestamp(-210866803200); -- 4714-11-24 00:00:00+00 BC - to_timestamp ---------------------------- - 4714-11-24 00:00:00+00 BC + to_timestamp +------------------------------ + 4714-11-24 00:00:00+00:00 BC (1 row) -- upper limit varies between integer and float timestamps, so hard to test @@ -2763,146 +2763,146 @@ SELECT to_timestamp('NaN'::float); ERROR: timestamp cannot be NaN SET TimeZone to 'Europe/Moscow'; SELECT '2011-03-26 21:00:00 UTC'::timestamptz; - timestamptz ------------------------- - 2011-03-27 00:00:00+03 + timestamptz +--------------------------- + 2011-03-27 00:00:00+03:00 (1 row) SELECT '2011-03-26 22:00:00 UTC'::timestamptz; - timestamptz ------------------------- - 2011-03-27 01:00:00+03 + timestamptz +--------------------------- + 2011-03-27 01:00:00+03:00 (1 row) SELECT '2011-03-26 22:59:59 UTC'::timestamptz; - timestamptz ------------------------- - 2011-03-27 01:59:59+03 + timestamptz +--------------------------- + 2011-03-27 01:59:59+03:00 (1 row) SELECT '2011-03-26 23:00:00 UTC'::timestamptz; - timestamptz ------------------------- - 2011-03-27 03:00:00+04 + timestamptz +--------------------------- + 2011-03-27 03:00:00+04:00 (1 row) SELECT '2011-03-26 23:00:01 UTC'::timestamptz; - timestamptz ------------------------- - 2011-03-27 03:00:01+04 + timestamptz +--------------------------- + 2011-03-27 03:00:01+04:00 (1 row) SELECT '2011-03-26 23:59:59 UTC'::timestamptz; - timestamptz ------------------------- - 2011-03-27 03:59:59+04 + timestamptz +--------------------------- + 2011-03-27 03:59:59+04:00 (1 row) SELECT '2011-03-27 00:00:00 UTC'::timestamptz; - timestamptz ------------------------- - 2011-03-27 04:00:00+04 + timestamptz +--------------------------- + 2011-03-27 04:00:00+04:00 (1 row) SELECT '2014-10-25 21:00:00 UTC'::timestamptz; - timestamptz ------------------------- - 2014-10-26 01:00:00+04 + timestamptz +--------------------------- + 2014-10-26 01:00:00+04:00 (1 row) SELECT '2014-10-25 21:59:59 UTC'::timestamptz; - timestamptz ------------------------- - 2014-10-26 01:59:59+04 + timestamptz +--------------------------- + 2014-10-26 01:59:59+04:00 (1 row) SELECT '2014-10-25 22:00:00 UTC'::timestamptz; - timestamptz ------------------------- - 2014-10-26 01:00:00+03 + timestamptz +--------------------------- + 2014-10-26 01:00:00+03:00 (1 row) SELECT '2014-10-25 22:00:01 UTC'::timestamptz; - timestamptz ------------------------- - 2014-10-26 01:00:01+03 + timestamptz +--------------------------- + 2014-10-26 01:00:01+03:00 (1 row) SELECT '2014-10-25 23:00:00 UTC'::timestamptz; - timestamptz ------------------------- - 2014-10-26 02:00:00+03 + timestamptz +--------------------------- + 2014-10-26 02:00:00+03:00 (1 row) RESET TimeZone; SELECT '2011-03-26 21:00:00 UTC'::timestamptz AT TIME ZONE 'Europe/Moscow'; - timezone + ?column? --------------------- 2011-03-27 00:00:00 (1 row) SELECT '2011-03-26 22:00:00 UTC'::timestamptz AT TIME ZONE 'Europe/Moscow'; - timezone + ?column? --------------------- 2011-03-27 01:00:00 (1 row) SELECT '2011-03-26 22:59:59 UTC'::timestamptz AT TIME ZONE 'Europe/Moscow'; - timezone + ?column? --------------------- 2011-03-27 01:59:59 (1 row) SELECT '2011-03-26 23:00:00 UTC'::timestamptz AT TIME ZONE 'Europe/Moscow'; - timezone + ?column? --------------------- 2011-03-27 03:00:00 (1 row) SELECT '2011-03-26 23:00:01 UTC'::timestamptz AT TIME ZONE 'Europe/Moscow'; - timezone + ?column? --------------------- 2011-03-27 03:00:01 (1 row) SELECT '2011-03-26 23:59:59 UTC'::timestamptz AT TIME ZONE 'Europe/Moscow'; - timezone + ?column? --------------------- 2011-03-27 03:59:59 (1 row) SELECT '2011-03-27 00:00:00 UTC'::timestamptz AT TIME ZONE 'Europe/Moscow'; - timezone + ?column? --------------------- 2011-03-27 04:00:00 (1 row) SELECT '2014-10-25 21:00:00 UTC'::timestamptz AT TIME ZONE 'Europe/Moscow'; - timezone + ?column? --------------------- 2014-10-26 01:00:00 (1 row) SELECT '2014-10-25 21:59:59 UTC'::timestamptz AT TIME ZONE 'Europe/Moscow'; - timezone + ?column? --------------------- 2014-10-26 01:59:59 (1 row) SELECT '2014-10-25 22:00:00 UTC'::timestamptz AT TIME ZONE 'Europe/Moscow'; - timezone + ?column? --------------------- 2014-10-26 01:00:00 (1 row) SELECT '2014-10-25 22:00:01 UTC'::timestamptz AT TIME ZONE 'Europe/Moscow'; - timezone + ?column? --------------------- 2014-10-26 01:00:01 (1 row) SELECT '2014-10-25 23:00:00 UTC'::timestamptz AT TIME ZONE 'Europe/Moscow'; - timezone + ?column? --------------------- 2014-10-26 02:00:00 (1 row) diff --git a/src/tests/regress/data/schedule b/src/tests/regress/data/schedule index 12a55796757d7..54cf97a5ed4d6 100644 --- a/src/tests/regress/data/schedule +++ b/src/tests/regress/data/schedule @@ -7,10 +7,9 @@ # interferes with crash-recovery testing. # test: tablespace -# test: boolean varchar text int2 int4 int8 float4 float8 comments -# test: strings date time timestamp interval -# test: case arrays delete -# test: jsonb jsonb_jsonpath -# test: regex -# test: contrib-pgcrypto-rijndael -test: timestamptz \ No newline at end of file +test: boolean varchar text int2 int4 int8 float4 float8 comments +test: strings date time timestamp interval +test: case arrays delete +test: jsonb jsonb_jsonpath +test: regex +test: contrib-pgcrypto-rijndael \ No newline at end of file From 3ead68f3446a6a8dcd7c7e10caf7d91c82211b84 Mon Sep 17 00:00:00 2001 From: chagelo Date: Sat, 23 Nov 2024 01:13:42 +0800 Subject: [PATCH 5/5] move testcases to ./e2e_test Signed-off-by: chagelo --- .../batch/functions/at_time_zone.slt.part | 11 - e2e_test/batch/functions/timezone.slt.part | 112 ++++ .../regress/data/expected/timestamptz.out | 553 +++++------------- src/tests/regress/data/sql/timestamptz.sql | 52 -- 4 files changed, 259 insertions(+), 469 deletions(-) create mode 100644 e2e_test/batch/functions/timezone.slt.part diff --git a/e2e_test/batch/functions/at_time_zone.slt.part b/e2e_test/batch/functions/at_time_zone.slt.part index 75a1e3a5d67ca..cfd89b3312965 100644 --- a/e2e_test/batch/functions/at_time_zone.slt.part +++ b/e2e_test/batch/functions/at_time_zone.slt.part @@ -37,14 +37,3 @@ select local AT TIME ZONE tz from t order by 1; statement ok drop table t; - -# timezone function -query T -select timezone('Europe/Moscow', '2014-10-25 22:00:00 UTC'::timestamptz); ----- -2014-10-26 01:00:00 - -query T -select timezone('Europe/Moscow', '2011-03-26 23:00:00 UTC'::timestamptz); ----- -2011-03-27 03:00:00 \ No newline at end of file diff --git a/e2e_test/batch/functions/timezone.slt.part b/e2e_test/batch/functions/timezone.slt.part new file mode 100644 index 0000000000000..344e00e735dc0 --- /dev/null +++ b/e2e_test/batch/functions/timezone.slt.part @@ -0,0 +1,112 @@ +statement ok +SET TimeZone to 'UTC'; + +query T +SELECT timezone('Europe/Moscow', '2011-03-27 02:00:00'::timestamp); +---- +2011-03-26 23:00:00+00:00 + +query T +SELECT timezone('Europe/Moscow', '2011-03-27 02:59:59'::timestamp); +---- +2011-03-26 23:59:59+00:00 + +query T +SELECT timezone('Europe/Moscow', '2011-03-27 03:00:00'::timestamp); +---- +2011-03-26 23:00:00+00:00 + +query T +SELECT timezone('Europe/Moscow', '2014-10-26 00:59:59'::timestamp); +---- +2014-10-25 20:59:59+00:00 + +query T +SELECT timezone('Europe/Moscow', '2014-10-26 01:00:00'::timestamp); +---- +2014-10-25 22:00:00+00:00 + +query T +SELECT timezone('Europe/Moscow', '2014-10-26 01:00:01'::timestamp); +---- +2014-10-25 22:00:01+00:00 + +query T +SELECT timezone('Asia/Shanghai', '2024-11-20 20:00:00 UTC'::timestamptz); +---- +2024-11-21 04:00:00 + +query T +SELECT timezone('Asia/Shanghai', '2023-02-28 20:00:00 UTC'::timestamptz); +---- +2023-03-01 04:00:00 + +query T +SELECT timezone('Asia/Shanghai', '2024-02-28 20:00:00 UTC'::timestamptz); +---- +2024-02-29 04:00:00 + +query T +SELECT timezone('Europe/Moscow', '2011-03-26 22:00:00 UTC'::timestamptz); +---- +2011-03-27 01:00:00 + +query T +SELECT timezone('Europe/Moscow', '2011-03-26 23:00:00 UTC'::timestamptz); +---- +2011-03-27 03:00:00 + +query T +SELECT timezone('Europe/Moscow', '2011-03-26 23:00:01 UTC'::timestamptz); +---- +2011-03-27 03:00:01 + +query T +SELECT timezone('Europe/Moscow', '2011-03-27 01:00:00 UTC'::timestamptz); +---- +2011-03-27 05:00:00 + +query T +SELECT timezone('Europe/Moscow', '2011-03-27 02:00:00 UTC'::timestamptz); +---- +2011-03-27 06:00:00 + +query T +SELECT timezone('Europe/Moscow', '2011-03-27 02:59:59 UTC'::timestamptz); +---- +2011-03-27 06:59:59 + +query T +SELECT timezone('Europe/Moscow', '2011-03-27 03:00:00 UTC'::timestamptz); +---- +2011-03-27 07:00:00 + +query T +SELECT timezone('Europe/Moscow', '2014-10-25 21:59:59 UTC'::timestamptz); +---- +2014-10-26 01:59:59 + +query T +SELECT timezone('Europe/Moscow', '2014-10-25 22:00:00 UTC'::timestamptz); +---- +2014-10-26 01:00:00 + +query T +SELECT timezone('Europe/Moscow', '2014-10-25 22:59:59 UTC'::timestamptz); +---- +2014-10-26 01:59:59 + +query T +SELECT timezone('Europe/Moscow', '2014-10-25 23:00:00 UTC'::timestamptz); +---- +2014-10-26 02:00:00 + +query T +SELECT timezone('Europe/Moscow', '2014-10-25 23:00:01 UTC'::timestamptz); +---- +2014-10-26 02:00:01 + +query T +SELECT timezone('Europe/Moscow', '2014-10-26 02:00:01 UTC'::timestamptz); +---- +2014-10-26 05:00:01 diff --git a/src/tests/regress/data/expected/timestamptz.out b/src/tests/regress/data/expected/timestamptz.out index 2512514fc1ceb..9b88cdf1916a1 100644 --- a/src/tests/regress/data/expected/timestamptz.out +++ b/src/tests/regress/data/expected/timestamptz.out @@ -2469,249 +2469,177 @@ SELECT '2014-10-26 02:00:00 MSK'::timestamptz; (1 row) SELECT '2011-03-27 00:00:00'::timestamp AT TIME ZONE 'Europe/Moscow'; - ?column? ---------------------------- - 2011-03-26 21:00:00+00:00 + timezone +------------------------ + 2011-03-26 21:00:00+00 (1 row) SELECT '2011-03-27 01:00:00'::timestamp AT TIME ZONE 'Europe/Moscow'; - ?column? ---------------------------- - 2011-03-26 22:00:00+00:00 + timezone +------------------------ + 2011-03-26 22:00:00+00 (1 row) SELECT '2011-03-27 01:59:59'::timestamp AT TIME ZONE 'Europe/Moscow'; - ?column? ---------------------------- - 2011-03-26 22:59:59+00:00 + timezone +------------------------ + 2011-03-26 22:59:59+00 (1 row) SELECT '2011-03-27 02:00:00'::timestamp AT TIME ZONE 'Europe/Moscow'; - ?column? ---------------------------- - 2011-03-26 23:00:00+00:00 + timezone +------------------------ + 2011-03-26 23:00:00+00 (1 row) SELECT '2011-03-27 02:00:01'::timestamp AT TIME ZONE 'Europe/Moscow'; - ?column? ---------------------------- - 2011-03-26 23:00:01+00:00 + timezone +------------------------ + 2011-03-26 23:00:01+00 (1 row) SELECT '2011-03-27 02:59:59'::timestamp AT TIME ZONE 'Europe/Moscow'; - ?column? ---------------------------- - 2011-03-26 23:59:59+00:00 + timezone +------------------------ + 2011-03-26 23:59:59+00 (1 row) SELECT '2011-03-27 03:00:00'::timestamp AT TIME ZONE 'Europe/Moscow'; - ?column? ---------------------------- - 2011-03-26 23:00:00+00:00 + timezone +------------------------ + 2011-03-26 23:00:00+00 (1 row) SELECT '2011-03-27 03:00:01'::timestamp AT TIME ZONE 'Europe/Moscow'; - ?column? ---------------------------- - 2011-03-26 23:00:01+00:00 + timezone +------------------------ + 2011-03-26 23:00:01+00 (1 row) SELECT '2011-03-27 04:00:00'::timestamp AT TIME ZONE 'Europe/Moscow'; - ?column? ---------------------------- - 2011-03-27 00:00:00+00:00 + timezone +------------------------ + 2011-03-27 00:00:00+00 (1 row) SELECT '2011-03-27 00:00:00'::timestamp AT TIME ZONE 'MSK'; - ?column? ---------------------------- - 2011-03-26 21:00:00+00:00 + timezone +------------------------ + 2011-03-26 21:00:00+00 (1 row) SELECT '2011-03-27 01:00:00'::timestamp AT TIME ZONE 'MSK'; - ?column? ---------------------------- - 2011-03-26 22:00:00+00:00 + timezone +------------------------ + 2011-03-26 22:00:00+00 (1 row) SELECT '2011-03-27 01:59:59'::timestamp AT TIME ZONE 'MSK'; - ?column? ---------------------------- - 2011-03-26 22:59:59+00:00 + timezone +------------------------ + 2011-03-26 22:59:59+00 (1 row) SELECT '2011-03-27 02:00:00'::timestamp AT TIME ZONE 'MSK'; - ?column? ---------------------------- - 2011-03-26 22:00:00+00:00 + timezone +------------------------ + 2011-03-26 22:00:00+00 (1 row) SELECT '2011-03-27 02:00:01'::timestamp AT TIME ZONE 'MSK'; - ?column? ---------------------------- - 2011-03-26 22:00:01+00:00 + timezone +------------------------ + 2011-03-26 22:00:01+00 (1 row) SELECT '2011-03-27 02:59:59'::timestamp AT TIME ZONE 'MSK'; - ?column? ---------------------------- - 2011-03-26 22:59:59+00:00 + timezone +------------------------ + 2011-03-26 22:59:59+00 (1 row) SELECT '2011-03-27 03:00:00'::timestamp AT TIME ZONE 'MSK'; - ?column? ---------------------------- - 2011-03-26 23:00:00+00:00 + timezone +------------------------ + 2011-03-26 23:00:00+00 (1 row) SELECT '2011-03-27 03:00:01'::timestamp AT TIME ZONE 'MSK'; - ?column? ---------------------------- - 2011-03-26 23:00:01+00:00 + timezone +------------------------ + 2011-03-26 23:00:01+00 (1 row) SELECT '2011-03-27 04:00:00'::timestamp AT TIME ZONE 'MSK'; - ?column? ---------------------------- - 2011-03-27 00:00:00+00:00 + timezone +------------------------ + 2011-03-27 00:00:00+00 (1 row) SELECT '2014-10-26 00:00:00'::timestamp AT TIME ZONE 'Europe/Moscow'; - ?column? ---------------------------- - 2014-10-25 20:00:00+00:00 + timezone +------------------------ + 2014-10-25 20:00:00+00 (1 row) SELECT '2014-10-26 00:59:59'::timestamp AT TIME ZONE 'Europe/Moscow'; - ?column? ---------------------------- - 2014-10-25 20:59:59+00:00 + timezone +------------------------ + 2014-10-25 20:59:59+00 (1 row) SELECT '2014-10-26 01:00:00'::timestamp AT TIME ZONE 'Europe/Moscow'; - ?column? ---------------------------- - 2014-10-25 22:00:00+00:00 + timezone +------------------------ + 2014-10-25 22:00:00+00 (1 row) SELECT '2014-10-26 01:00:01'::timestamp AT TIME ZONE 'Europe/Moscow'; - ?column? ---------------------------- - 2014-10-25 22:00:01+00:00 + timezone +------------------------ + 2014-10-25 22:00:01+00 (1 row) SELECT '2014-10-26 02:00:00'::timestamp AT TIME ZONE 'Europe/Moscow'; - ?column? ---------------------------- - 2014-10-25 23:00:00+00:00 + timezone +------------------------ + 2014-10-25 23:00:00+00 (1 row) SELECT '2014-10-26 00:00:00'::timestamp AT TIME ZONE 'MSK'; - ?column? ---------------------------- - 2014-10-25 20:00:00+00:00 + timezone +------------------------ + 2014-10-25 20:00:00+00 (1 row) SELECT '2014-10-26 00:59:59'::timestamp AT TIME ZONE 'MSK'; - ?column? ---------------------------- - 2014-10-25 20:59:59+00:00 + timezone +------------------------ + 2014-10-25 20:59:59+00 (1 row) SELECT '2014-10-26 01:00:00'::timestamp AT TIME ZONE 'MSK'; - ?column? ---------------------------- - 2014-10-25 22:00:00+00:00 + timezone +------------------------ + 2014-10-25 22:00:00+00 (1 row) SELECT '2014-10-26 01:00:01'::timestamp AT TIME ZONE 'MSK'; - ?column? ---------------------------- - 2014-10-25 22:00:01+00:00 + timezone +------------------------ + 2014-10-25 22:00:01+00 (1 row) SELECT '2014-10-26 02:00:00'::timestamp AT TIME ZONE 'MSK'; - ?column? ---------------------------- - 2014-10-25 23:00:00+00:00 -(1 row) - -SELECT timezone('Europe/Moscow', '2011-03-27 02:00:00'::timestamp); - timezone ---------------------------- - 2011-03-26 23:00:00+00:00 -(1 row) - -SELECT timezone('Europe/Moscow', '2011-03-27 02:59:59'::timestamp); - timezone ---------------------------- - 2011-03-26 23:59:59+00:00 -(1 row) - -SELECT timezone('Europe/Moscow', '2011-03-27 03:00:00'::timestamp); - timezone ---------------------------- - 2011-03-26 23:00:00+00:00 -(1 row) - -SELECT timezone('MSK', '2011-03-27 02:00:00'::timestamp); - timezone ---------------------------- - 2011-03-26 22:00:00+00:00 -(1 row) - -SELECT timezone('MSK', '2011-03-27 02:59:59'::timestamp); - timezone ---------------------------- - 2011-03-26 22:59:59+00:00 -(1 row) - -SELECT timezone('MSK', '2011-03-27 03:00:00'::timestamp); - timezone ---------------------------- - 2011-03-26 23:00:00+00:00 -(1 row) - -SELECT timezone('Europe/Moscow', '2014-10-26 00:59:59'::timestamp); - timezone ---------------------------- - 2014-10-25 20:59:59+00:00 -(1 row) - -SELECT timezone('Europe/Moscow', '2014-10-26 01:00:00'::timestamp); - timezone ---------------------------- - 2014-10-25 22:00:00+00:00 -(1 row) - -SELECT timezone('Europe/Moscow', '2014-10-26 01:00:01'::timestamp); - timezone ---------------------------- - 2014-10-25 22:00:01+00:00 -(1 row) - -SELECT timezone('MSK', '2014-10-26 00:59:59'::timestamp); - timezone ---------------------------- - 2014-10-25 20:59:59+00:00 -(1 row) - -SELECT timezone('MSK', '2014-10-26 01:00:00'::timestamp); - timezone ---------------------------- - 2014-10-25 22:00:00+00:00 -(1 row) - -SELECT timezone('MSK', '2014-10-26 01:00:01'::timestamp); - timezone ---------------------------- - 2014-10-25 22:00:01+00:00 + timezone +------------------------ + 2014-10-25 23:00:00+00 (1 row) SELECT make_timestamptz(2014, 10, 26, 0, 0, 0, 'MSK'); - make_timestamptz ---------------------------- - 2014-10-25 20:00:00+00:00 + make_timestamptz +------------------------ + 2014-10-25 20:00:00+00 (1 row) SELECT make_timestamptz(2014, 10, 26, 1, 0, 0, 'MSK'); @@ -2721,28 +2649,28 @@ SELECT make_timestamptz(2014, 10, 26, 1, 0, 0, 'MSK'); (1 row) SELECT to_timestamp( 0); -- 1970-01-01 00:00:00+00 - to_timestamp ---------------------------- - 1970-01-01 00:00:00+00:00 + to_timestamp +------------------------ + 1970-01-01 00:00:00+00 (1 row) SELECT to_timestamp( 946684800); -- 2000-01-01 00:00:00+00 - to_timestamp ---------------------------- - 2000-01-01 00:00:00+00:00 + to_timestamp +------------------------ + 2000-01-01 00:00:00+00 (1 row) SELECT to_timestamp(1262349296.7890123); -- 2010-01-01 12:34:56.789012+00 - to_timestamp ----------------------------------- - 2010-01-01 12:34:56.789012+00:00 + to_timestamp +------------------------------- + 2010-01-01 12:34:56.789012+00 (1 row) -- edge cases SELECT to_timestamp(-210866803200); -- 4714-11-24 00:00:00+00 BC - to_timestamp ------------------------------- - 4714-11-24 00:00:00+00:00 BC + to_timestamp +--------------------------- + 4714-11-24 00:00:00+00 BC (1 row) -- upper limit varies between integer and float timestamps, so hard to test @@ -2763,146 +2691,146 @@ SELECT to_timestamp('NaN'::float); ERROR: timestamp cannot be NaN SET TimeZone to 'Europe/Moscow'; SELECT '2011-03-26 21:00:00 UTC'::timestamptz; - timestamptz ---------------------------- - 2011-03-27 00:00:00+03:00 + timestamptz +------------------------ + 2011-03-27 00:00:00+03 (1 row) SELECT '2011-03-26 22:00:00 UTC'::timestamptz; - timestamptz ---------------------------- - 2011-03-27 01:00:00+03:00 + timestamptz +------------------------ + 2011-03-27 01:00:00+03 (1 row) SELECT '2011-03-26 22:59:59 UTC'::timestamptz; - timestamptz ---------------------------- - 2011-03-27 01:59:59+03:00 + timestamptz +------------------------ + 2011-03-27 01:59:59+03 (1 row) SELECT '2011-03-26 23:00:00 UTC'::timestamptz; - timestamptz ---------------------------- - 2011-03-27 03:00:00+04:00 + timestamptz +------------------------ + 2011-03-27 03:00:00+04 (1 row) SELECT '2011-03-26 23:00:01 UTC'::timestamptz; - timestamptz ---------------------------- - 2011-03-27 03:00:01+04:00 + timestamptz +------------------------ + 2011-03-27 03:00:01+04 (1 row) SELECT '2011-03-26 23:59:59 UTC'::timestamptz; - timestamptz ---------------------------- - 2011-03-27 03:59:59+04:00 + timestamptz +------------------------ + 2011-03-27 03:59:59+04 (1 row) SELECT '2011-03-27 00:00:00 UTC'::timestamptz; - timestamptz ---------------------------- - 2011-03-27 04:00:00+04:00 + timestamptz +------------------------ + 2011-03-27 04:00:00+04 (1 row) SELECT '2014-10-25 21:00:00 UTC'::timestamptz; - timestamptz ---------------------------- - 2014-10-26 01:00:00+04:00 + timestamptz +------------------------ + 2014-10-26 01:00:00+04 (1 row) SELECT '2014-10-25 21:59:59 UTC'::timestamptz; - timestamptz ---------------------------- - 2014-10-26 01:59:59+04:00 + timestamptz +------------------------ + 2014-10-26 01:59:59+04 (1 row) SELECT '2014-10-25 22:00:00 UTC'::timestamptz; - timestamptz ---------------------------- - 2014-10-26 01:00:00+03:00 + timestamptz +------------------------ + 2014-10-26 01:00:00+03 (1 row) SELECT '2014-10-25 22:00:01 UTC'::timestamptz; - timestamptz ---------------------------- - 2014-10-26 01:00:01+03:00 + timestamptz +------------------------ + 2014-10-26 01:00:01+03 (1 row) SELECT '2014-10-25 23:00:00 UTC'::timestamptz; - timestamptz ---------------------------- - 2014-10-26 02:00:00+03:00 + timestamptz +------------------------ + 2014-10-26 02:00:00+03 (1 row) RESET TimeZone; SELECT '2011-03-26 21:00:00 UTC'::timestamptz AT TIME ZONE 'Europe/Moscow'; - ?column? + timezone --------------------- 2011-03-27 00:00:00 (1 row) SELECT '2011-03-26 22:00:00 UTC'::timestamptz AT TIME ZONE 'Europe/Moscow'; - ?column? + timezone --------------------- 2011-03-27 01:00:00 (1 row) SELECT '2011-03-26 22:59:59 UTC'::timestamptz AT TIME ZONE 'Europe/Moscow'; - ?column? + timezone --------------------- 2011-03-27 01:59:59 (1 row) SELECT '2011-03-26 23:00:00 UTC'::timestamptz AT TIME ZONE 'Europe/Moscow'; - ?column? + timezone --------------------- 2011-03-27 03:00:00 (1 row) SELECT '2011-03-26 23:00:01 UTC'::timestamptz AT TIME ZONE 'Europe/Moscow'; - ?column? + timezone --------------------- 2011-03-27 03:00:01 (1 row) SELECT '2011-03-26 23:59:59 UTC'::timestamptz AT TIME ZONE 'Europe/Moscow'; - ?column? + timezone --------------------- 2011-03-27 03:59:59 (1 row) SELECT '2011-03-27 00:00:00 UTC'::timestamptz AT TIME ZONE 'Europe/Moscow'; - ?column? + timezone --------------------- 2011-03-27 04:00:00 (1 row) SELECT '2014-10-25 21:00:00 UTC'::timestamptz AT TIME ZONE 'Europe/Moscow'; - ?column? + timezone --------------------- 2014-10-26 01:00:00 (1 row) SELECT '2014-10-25 21:59:59 UTC'::timestamptz AT TIME ZONE 'Europe/Moscow'; - ?column? + timezone --------------------- 2014-10-26 01:59:59 (1 row) SELECT '2014-10-25 22:00:00 UTC'::timestamptz AT TIME ZONE 'Europe/Moscow'; - ?column? + timezone --------------------- 2014-10-26 01:00:00 (1 row) SELECT '2014-10-25 22:00:01 UTC'::timestamptz AT TIME ZONE 'Europe/Moscow'; - ?column? + timezone --------------------- 2014-10-26 01:00:01 (1 row) SELECT '2014-10-25 23:00:00 UTC'::timestamptz AT TIME ZONE 'Europe/Moscow'; - ?column? + timezone --------------------- 2014-10-26 02:00:00 (1 row) @@ -2979,193 +2907,6 @@ SELECT '2014-10-25 23:00:00 UTC'::timestamptz AT TIME ZONE 'MSK'; 2014-10-26 02:00:00 (1 row) -SELECT timezone('Asia/Shanghai', '2024-11-20 20:00:00 UTC'::timestamptz); - timezone ---------------------- - 2024-11-21 04:00:00 -(1 row) - -SELECT timezone('Asia/Shanghai', '2023-02-28 20:00:00 UTC'::timestamptz); - timezone ---------------------- - 2023-03-01 04:00:00 -(1 row) - -SELECT timezone('Asia/Shanghai', '2024-02-28 20:00:00 UTC'::timestamptz); - timezone ---------------------- - 2024-02-29 04:00:00 -(1 row) - -SELECT timezone('Europe/Moscow', '2011-03-26 22:00:00 UTC'::timestamptz); - timezone ---------------------- - 2011-03-27 01:00:00 -(1 row) - -SELECT timezone('Europe/Moscow', '2011-03-26 22:59:59 UTC'::timestamptz); - timezone ---------------------- - 2011-03-27 01:59:59 -(1 row) - -SELECT timezone('Europe/Moscow', '2011-03-26 23:00:00 UTC'::timestamptz); - timezone ---------------------- - 2011-03-27 03:00:00 -(1 row) - -SELECT timezone('Europe/Moscow', '2011-03-26 23:00:01 UTC'::timestamptz); - timezone ---------------------- - 2011-03-27 03:00:01 -(1 row) - -SELECT timezone('Europe/Moscow', '2011-03-27 01:00:00 UTC'::timestamptz); - timezone ---------------------- - 2011-03-27 05:00:00 -(1 row) - -SELECT timezone('Europe/Moscow', '2011-03-27 02:00:00 UTC'::timestamptz); - timezone ---------------------- - 2011-03-27 06:00:00 -(1 row) - -SELECT timezone('Europe/Moscow', '2011-03-27 02:59:59 UTC'::timestamptz); - timezone ---------------------- - 2011-03-27 06:59:59 -(1 row) - -SELECT timezone('Europe/Moscow', '2011-03-27 03:00:00 UTC'::timestamptz); - timezone ---------------------- - 2011-03-27 07:00:00 -(1 row) - -SELECT timezone('MSK', '2011-03-26 22:00:00 UTC'::timestamptz); - timezone ---------------------- - 2011-03-27 01:00:00 -(1 row) - -SELECT timezone('MSK', '2011-03-26 22:59:59 UTC'::timestamptz); - timezone ---------------------- - 2011-03-27 01:59:59 -(1 row) - -SELECT timezone('MSK', '2011-03-26 23:00:00 UTC'::timestamptz); - timezone ---------------------- - 2011-03-27 03:00:00 -(1 row) - -SELECT timezone('MSK', '2011-03-26 23:00:01 UTC'::timestamptz); - timezone ---------------------- - 2011-03-27 03:00:01 -(1 row) - -SELECT timezone('MSK', '2011-03-27 01:00:00 UTC'::timestamptz); - timezone ---------------------- - 2011-03-27 05:00:00 -(1 row) - -SELECT timezone('MSK', '2011-03-27 02:00:00 UTC'::timestamptz); - timezone ---------------------- - 2011-03-27 06:00:00 -(1 row) - -SELECT timezone('MSK', '2011-03-27 02:59:59 UTC'::timestamptz); - timezone ---------------------- - 2011-03-27 06:59:59 -(1 row) - -SELECT timezone('MSK', '2011-03-27 03:00:00 UTC'::timestamptz); - timezone ---------------------- - 2011-03-27 07:00:00 -(1 row) - - -SELECT timezone('Europe/Moscow', '2014-10-25 21:59:59 UTC'::timestamptz); - timezone ---------------------- - 2014-10-26 01:59:59 -(1 row) - -SELECT timezone('Europe/Moscow', '2014-10-25 22:00:00 UTC'::timestamptz); - timezone ---------------------- - 2014-10-26 01:00:00 -(1 row) - -SELECT timezone('Europe/Moscow', '2014-10-25 22:59:59 UTC'::timestamptz); - timezone ---------------------- - 2014-10-26 01:59:59 -(1 row) - -SELECT timezone('Europe/Moscow', '2014-10-25 23:00:00 UTC'::timestamptz); - timezone ---------------------- - 2014-10-26 02:00:00 -(1 row) - -SELECT timezone('Europe/Moscow', '2014-10-25 23:00:01 UTC'::timestamptz); - timezone ---------------------- - 2014-10-26 02:00:01 -(1 row) - -SELECT timezone('Europe/Moscow', '2014-10-26 02:00:01 UTC'::timestamptz); - timezone ---------------------- - 2014-10-26 05:00:01 -(1 row) - -SELECT timezone('MSK', '2014-10-25 21:59:59 UTC'::timestamptz); - timezone ---------------------- - 2014-10-26 01:59:59 -(1 row) - -SELECT timezone('MSK', '2014-10-25 22:00:00 UTC'::timestamptz); - timezone ---------------------- - 2014-10-26 01:00:00 -(1 row) - -SELECT timezone('MSK', '2014-10-25 22:59:59 UTC'::timestamptz); - timezone ---------------------- - 2014-10-26 01:59:59 -(1 row) - -SELECT timezone('MSK', '2014-10-25 23:00:00 UTC'::timestamptz); - timezone ---------------------- - 2014-10-26 02:00:00 -(1 row) - -SELECT timezone('MSK', '2014-10-25 23:00:01 UTC'::timestamptz); - timezone ---------------------- - 2014-10-26 02:00:01 -(1 row) - -SELECT timezone('MSK', '2014-10-26 02:00:01 UTC'::timestamptz); - timezone ---------------------- - 2014-10-26 05:00:01 -(1 row) - -- -- Test that AT TIME ZONE isn't misoptimized when using an index (bug #14504) -- diff --git a/src/tests/regress/data/sql/timestamptz.sql b/src/tests/regress/data/sql/timestamptz.sql index c1b34a3503a16..ca2877024d58d 100644 --- a/src/tests/regress/data/sql/timestamptz.sql +++ b/src/tests/regress/data/sql/timestamptz.sql @@ -480,22 +480,6 @@ SELECT '2014-10-26 01:00:00'::timestamp AT TIME ZONE 'MSK'; SELECT '2014-10-26 01:00:01'::timestamp AT TIME ZONE 'MSK'; SELECT '2014-10-26 02:00:00'::timestamp AT TIME ZONE 'MSK'; -SELECT timezone('Europe/Moscow', '2011-03-27 02:00:00'::timestamp); -SELECT timezone('Europe/Moscow', '2011-03-27 02:59:59'::timestamp); -SELECT timezone('Europe/Moscow', '2011-03-27 03:00:00'::timestamp); - -SELECT timezone('MSK', '2011-03-27 02:00:00'::timestamp); -SELECT timezone('MSK', '2011-03-27 02:59:59'::timestamp); -SELECT timezone('MSK', '2011-03-27 03:00:00'::timestamp); - -SELECT timezone('Europe/Moscow', '2014-10-26 00:59:59'::timestamp); -SELECT timezone('Europe/Moscow', '2014-10-26 01:00:00'::timestamp); -SELECT timezone('Europe/Moscow', '2014-10-26 01:00:01'::timestamp); - -SELECT timezone('MSK', '2014-10-26 00:59:59'::timestamp); -SELECT timezone('MSK', '2014-10-26 01:00:00'::timestamp); -SELECT timezone('MSK', '2014-10-26 01:00:01'::timestamp); - SELECT make_timestamptz(2014, 10, 26, 0, 0, 0, 'MSK'); SELECT make_timestamptz(2014, 10, 26, 1, 0, 0, 'MSK'); @@ -557,42 +541,6 @@ SELECT '2014-10-25 22:00:00 UTC'::timestamptz AT TIME ZONE 'MSK'; SELECT '2014-10-25 22:00:01 UTC'::timestamptz AT TIME ZONE 'MSK'; SELECT '2014-10-25 23:00:00 UTC'::timestamptz AT TIME ZONE 'MSK'; -SELECT timezone('Asia/Shanghai', '2024-11-20 20:00:00 UTC'::timestamptz); -SELECT timezone('Asia/Shanghai', '2023-02-28 20:00:00 UTC'::timestamptz); -SELECT timezone('Asia/Shanghai', '2024-02-28 20:00:00 UTC'::timestamptz); - -SELECT timezone('Europe/Moscow', '2011-03-26 22:00:00 UTC'::timestamptz); -SELECT timezone('Europe/Moscow', '2011-03-26 22:59:59 UTC'::timestamptz); -SELECT timezone('Europe/Moscow', '2011-03-26 23:00:00 UTC'::timestamptz); -SELECT timezone('Europe/Moscow', '2011-03-26 23:00:01 UTC'::timestamptz); -SELECT timezone('Europe/Moscow', '2011-03-27 01:00:00 UTC'::timestamptz); -SELECT timezone('Europe/Moscow', '2011-03-27 02:00:00 UTC'::timestamptz); -SELECT timezone('Europe/Moscow', '2011-03-27 02:59:59 UTC'::timestamptz); -SELECT timezone('Europe/Moscow', '2011-03-27 03:00:00 UTC'::timestamptz); - -SELECT timezone('MSK', '2011-03-26 22:00:00 UTC'::timestamptz); -SELECT timezone('MSK', '2011-03-26 22:59:59 UTC'::timestamptz); -SELECT timezone('MSK', '2011-03-26 23:00:00 UTC'::timestamptz); -SELECT timezone('MSK', '2011-03-26 23:00:01 UTC'::timestamptz); -SELECT timezone('MSK', '2011-03-27 01:00:00 UTC'::timestamptz); -SELECT timezone('MSK', '2011-03-27 02:00:00 UTC'::timestamptz); -SELECT timezone('MSK', '2011-03-27 02:59:59 UTC'::timestamptz); -SELECT timezone('MSK', '2011-03-27 03:00:00 UTC'::timestamptz); - -SELECT timezone('Europe/Moscow', '2014-10-25 21:59:59 UTC'::timestamptz); -SELECT timezone('Europe/Moscow', '2014-10-25 22:00:00 UTC'::timestamptz); -SELECT timezone('Europe/Moscow', '2014-10-25 22:59:59 UTC'::timestamptz); -SELECT timezone('Europe/Moscow', '2014-10-25 23:00:00 UTC'::timestamptz); -SELECT timezone('Europe/Moscow', '2014-10-25 23:00:01 UTC'::timestamptz); -SELECT timezone('Europe/Moscow', '2014-10-26 02:00:01 UTC'::timestamptz); - -SELECT timezone('MSK', '2014-10-25 21:59:59 UTC'::timestamptz); -SELECT timezone('MSK', '2014-10-25 22:00:00 UTC'::timestamptz); -SELECT timezone('MSK', '2014-10-25 22:59:59 UTC'::timestamptz); -SELECT timezone('MSK', '2014-10-25 23:00:00 UTC'::timestamptz); -SELECT timezone('MSK', '2014-10-25 23:00:01 UTC'::timestamptz); -SELECT timezone('MSK', '2014-10-26 02:00:01 UTC'::timestamptz); - -- -- Test that AT TIME ZONE isn't misoptimized when using an index (bug #14504) --