diff --git a/src/common/backend/catalog/builtin_funcs.ini b/src/common/backend/catalog/builtin_funcs.ini index 4a2ae622a..8d614ddc9 100644 --- a/src/common/backend/catalog/builtin_funcs.ini +++ b/src/common/backend/catalog/builtin_funcs.ini @@ -7288,6 +7288,10 @@ "network_supeq", 1, AddBuiltinFunc(_0(930), _1("network_supeq"), _2(2), _3(true), _4(false), _5(network_supeq), _6(16), _7(PG_CATALOG_NAMESPACE), _8(BOOTSTRAP_SUPERUSERID), _9(INTERNALlanguageId), _10(1), _11(0), _12(0), _13(0), _14(false), _15(false), _16(false), _17(false), _18('i'), _19(0), _20(2, 869, 869), _21(NULL), _22(NULL), _23(NULL), _24(NULL), _25("network_supeq"), _26(NULL), _27(NULL), _28(NULL), _29(0), _30(false), _31(NULL), _32(false), _33(NULL), _34('f'), _35(NULL), _36(0), _37(false), _38(NULL), _39(NULL), _40(0)) ), + AddFuncGroup( + "new_time", 1, + AddBuiltinFunc(_0(970), _1("new_time"), _2(3), _3(true), _4(false), _5(new_time), _6(1114), _7(PG_CATALOG_NAMESPACE), _8(BOOTSTRAP_SUPERUSERID), _9(INTERNALlanguageId), _10(1), _11(0), _12(0), _13(0), _14(false), _15(false), _16(false), _17(false), _18('i'), _19(0), _20(3, 1114, 25, 25), _21(NULL), _22(NULL), _23(NULL), _24(NULL), _25("new_time"), _26(NULL), _27(NULL), _28(NULL), _29(0), _30(false), _31(NULL), _32(false), _33("convert date and time in timezone1 to timezone2"), _34('f'), _35(NULL), _36(0), _37(false), _38(NULL), _39(NULL), _40(0)), + ), AddFuncGroup( "next", 1, AddBuiltinFunc(_0(1502), _1("next"), _2(0), _3(true), _4(true), _5(debug_client_next), _6(2249), _7(PG_PLDEBUG_NAMESPACE), _8(BOOTSTRAP_SUPERUSERID), _9(INTERNALlanguageId), _10(1), _11(1), _12(0), _13(0), _14(false), _15(false), _16(false), _17(false), _18('s'), _19(0), _20(0),_21(4, 26, 25, 23, 25), _22(4, 'o', 'o', 'o', 'o'), _23(4, "funcoid", "funcname", "lineno", "query"), _24(NULL), _25("debug_client_next"), _26(NULL), _27(NULL), _28(NULL), _29(0), _30(false), _31(false), _32(false), _33(NULL), _34('f'), _35(NULL), _36(0), _37(false), _38(NULL), _39(NULL), _40(0)), diff --git a/src/common/backend/utils/adt/timestamp.cpp b/src/common/backend/utils/adt/timestamp.cpp index 993072e7b..608a699b8 100644 --- a/src/common/backend/utils/adt/timestamp.cpp +++ b/src/common/backend/utils/adt/timestamp.cpp @@ -1532,6 +1532,23 @@ static void EncodeSpecialTimestamp(Timestamp dt, char* str) } } +Datum new_time(PG_FUNCTION_ARGS) +{ + if (!DB_IS_CMPT(A_FORMAT)) { + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), errmsg("NEW_TIME is only supported in A compatibility database."))); + } + Timestamp dt = PG_GETARG_TIMESTAMP(0); + text *timezone1 = PG_GETARG_TEXT_PP(1); + text *timezone2 = PG_GETARG_TEXT_PP(2); + + Timestamp result = DirectFunctionCall2( + timestamptz_zone, PointerGetDatum(timezone2), + TimestampTzGetDatum(DirectFunctionCall2(timestamp_zone, PointerGetDatum(timezone1), TimestampGetDatum(dt)))); + AdjustTimestampForTypmod(&result, 0); + PG_RETURN_TIMESTAMP(result); +} + Datum now(PG_FUNCTION_ARGS) { PG_RETURN_TIMESTAMPTZ(GetCurrentTransactionStartTimestamp()); diff --git a/src/common/backend/utils/init/globals.cpp b/src/common/backend/utils/init/globals.cpp index ed721faec..40e37a6ac 100644 --- a/src/common/backend/utils/init/globals.cpp +++ b/src/common/backend/utils/init/globals.cpp @@ -77,7 +77,7 @@ bool will_shutdown = false; * ********************************************/ -const uint32 GRAND_VERSION_NUM = 93006; +const uint32 GRAND_VERSION_NUM = 93007; /******************************************** * 2.VERSION NUM FOR EACH FEATURE diff --git a/src/include/catalog/upgrade_sql/rollback_catalog_maindb/rollback-post_catalog_maindb_93_007.sql b/src/include/catalog/upgrade_sql/rollback_catalog_maindb/rollback-post_catalog_maindb_93_007.sql new file mode 100644 index 000000000..be79d46a8 --- /dev/null +++ b/src/include/catalog/upgrade_sql/rollback_catalog_maindb/rollback-post_catalog_maindb_93_007.sql @@ -0,0 +1 @@ +DROP FUNCTION IF EXISTS pg_catalog.new_time(timestamp, text, text); \ No newline at end of file diff --git a/src/include/catalog/upgrade_sql/rollback_catalog_otherdb/rollback-post_catalog_otherdb_93_007.sql b/src/include/catalog/upgrade_sql/rollback_catalog_otherdb/rollback-post_catalog_otherdb_93_007.sql new file mode 100644 index 000000000..be79d46a8 --- /dev/null +++ b/src/include/catalog/upgrade_sql/rollback_catalog_otherdb/rollback-post_catalog_otherdb_93_007.sql @@ -0,0 +1 @@ +DROP FUNCTION IF EXISTS pg_catalog.new_time(timestamp, text, text); \ No newline at end of file diff --git a/src/include/catalog/upgrade_sql/upgrade_catalog_maindb/upgrade-post_catalog_maindb_93_007.sql b/src/include/catalog/upgrade_sql/upgrade_catalog_maindb/upgrade-post_catalog_maindb_93_007.sql new file mode 100644 index 000000000..9fcd5f304 --- /dev/null +++ b/src/include/catalog/upgrade_sql/upgrade_catalog_maindb/upgrade-post_catalog_maindb_93_007.sql @@ -0,0 +1,4 @@ +SET LOCAL inplace_upgrade_next_system_object_oids = IUO_PROC, 970; +CREATE FUNCTION pg_catalog.new_time(timestamp, text, text) +RETURNS record LANGUAGE INTERNAL IMMUTABLE STRICT as 'new_time'; +COMMENT ON FUNCTION pg_catalog.new_time(timestamp, text, text) IS 'convert date and time in timezone1 to timezone2'; \ No newline at end of file diff --git a/src/include/catalog/upgrade_sql/upgrade_catalog_otherdb/upgrade-post_catalog_otherdb_93_007.sql b/src/include/catalog/upgrade_sql/upgrade_catalog_otherdb/upgrade-post_catalog_otherdb_93_007.sql new file mode 100644 index 000000000..9fcd5f304 --- /dev/null +++ b/src/include/catalog/upgrade_sql/upgrade_catalog_otherdb/upgrade-post_catalog_otherdb_93_007.sql @@ -0,0 +1,4 @@ +SET LOCAL inplace_upgrade_next_system_object_oids = IUO_PROC, 970; +CREATE FUNCTION pg_catalog.new_time(timestamp, text, text) +RETURNS record LANGUAGE INTERNAL IMMUTABLE STRICT as 'new_time'; +COMMENT ON FUNCTION pg_catalog.new_time(timestamp, text, text) IS 'convert date and time in timezone1 to timezone2'; \ No newline at end of file diff --git a/src/include/utils/timestamp.h b/src/include/utils/timestamp.h index ee51492b9..6d0304758 100644 --- a/src/include/utils/timestamp.h +++ b/src/include/utils/timestamp.h @@ -248,6 +248,7 @@ extern Datum timestamptz_trunc(PG_FUNCTION_ARGS); extern Datum timestamptz_trunc_alias(PG_FUNCTION_ARGS); extern Datum timestamptz_part(PG_FUNCTION_ARGS); +extern Datum new_time(PG_FUNCTION_ARGS); extern Datum now(PG_FUNCTION_ARGS); extern Datum statement_timestamp(PG_FUNCTION_ARGS); extern Datum clock_timestamp(PG_FUNCTION_ARGS); diff --git a/src/test/regress/expected/hw_functions.out b/src/test/regress/expected/hw_functions.out index c4a63298f..72e7ac77b 100644 --- a/src/test/regress/expected/hw_functions.out +++ b/src/test/regress/expected/hw_functions.out @@ -543,4 +543,54 @@ select func_get_subpartition_filepath('test_func_subpartition_table', 'p1', 'p1_ drop function func_get_subpartition_filepath; drop table test_func_subpartition_table; +SET datestyle = 'ISO, YMD'; +select new_time('2024-07-22', 'EST', 'PST'); + new_time +--------------------- + 2024-07-21 21:00:00 +(1 row) + +select new_time('2024-07-22 14:00:00', 'EST', 'PST'); + new_time +--------------------- + 2024-07-22 11:00:00 +(1 row) + +select new_time(to_date('2024-07-22 14:00:00', 'YYYY-MM-DD HH24:MI:SS'), 'EST', 'PST'); + new_time +--------------------- + 2024-07-22 11:00:00 +(1 row) + +select new_time('2024-09-09 15:27:26.114841 +01:00', 'EST', 'PST'); + new_time +--------------------- + 2024-09-09 12:27:26 +(1 row) + +select new_time('2024-07-22 14:00:00', '5:00', 'PST'); + new_time +--------------------- + 2024-07-22 11:00:00 +(1 row) + +select new_time('2024-07-22 14:00:00', 'Europe/Copenhagen', 'PST'); + new_time +--------------------- + 2024-07-22 04:00:00 +(1 row) + +select new_time(now(), 'EST', 'PST'); +ERROR: function new_time(timestamp with time zone, unknown, unknown) does not exist +LINE 1: select new_time(now(), 'EST', 'PST'); + ^ +HINT: No function matches the given name and argument types. You might need to add explicit type casts. +CONTEXT: referenced column: new_time +create database db_mysql dbcompatibility = 'B'; +\c db_mysql +select new_time('2024-07-22', 'EST', 'PST'); +ERROR: NEW_TIME is only supported in A compatibility database. +CONTEXT: referenced column: new_time +\c regression +drop database db_mysql; drop schema basefunc cascade; diff --git a/src/test/regress/sql/hw_functions.sql b/src/test/regress/sql/hw_functions.sql index 55f75da84..57f948dda 100644 --- a/src/test/regress/sql/hw_functions.sql +++ b/src/test/regress/sql/hw_functions.sql @@ -271,4 +271,20 @@ select func_get_subpartition_filepath('test_func_subpartition_table', 'p1', 'p1_ drop function func_get_subpartition_filepath; drop table test_func_subpartition_table; +SET datestyle = 'ISO, YMD'; + +select new_time('2024-07-22', 'EST', 'PST'); +select new_time('2024-07-22 14:00:00', 'EST', 'PST'); +select new_time(to_date('2024-07-22 14:00:00', 'YYYY-MM-DD HH24:MI:SS'), 'EST', 'PST'); +select new_time('2024-09-09 15:27:26.114841 +01:00', 'EST', 'PST'); +select new_time('2024-07-22 14:00:00', '5:00', 'PST'); +select new_time('2024-07-22 14:00:00', 'Europe/Copenhagen', 'PST'); +select new_time(now(), 'EST', 'PST'); + +create database db_mysql dbcompatibility = 'B'; +\c db_mysql +select new_time('2024-07-22', 'EST', 'PST'); +\c regression +drop database db_mysql; + drop schema basefunc cascade;