diff --git a/e2e_test/batch/functions/at_time_zone.slt.part b/e2e_test/batch/functions/at_time_zone.slt.part index cfd89b331296..75a1e3a5d67c 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 a91d0ac173c2..e56668c99044 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 75a53f8a4b3c..06f9f2a7ffba 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 61892829dbf6..7570f72c5d09 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 a70efbe91a79..83a8cfa537ba 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 e99a3260497c..c53bde642ad3 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 4677335daebb..2512514fc1ce 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 12a55796757d..54cf97a5ed4d 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