[A兼容性]支持new_time函数

This commit is contained in:
maxz
2024-10-17 10:05:24 +08:00
parent 8ffda701dc
commit 1389181053
10 changed files with 99 additions and 1 deletions

View File

@ -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)),

View File

@ -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());

View File

@ -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

View File

@ -0,0 +1 @@
DROP FUNCTION IF EXISTS pg_catalog.new_time(timestamp, text, text);

View File

@ -0,0 +1 @@
DROP FUNCTION IF EXISTS pg_catalog.new_time(timestamp, text, text);

View File

@ -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';

View File

@ -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';

View File

@ -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);

View File

@ -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;

View File

@ -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;