From ec0816358bfdb9a651b065025dd96af68f6c1c1b Mon Sep 17 00:00:00 2001 From: li-qinlang Date: Wed, 20 Sep 2023 16:15:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dtime=5Fbool&date=5Fbool?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../b_compatibility_time_funcs.out | 121 ++++++++++++++++++ contrib/dolphin/plugin_utils/adt/date.cpp | 12 +- .../b_compatibility_time_funcs.sql | 20 +++ 3 files changed, 147 insertions(+), 6 deletions(-) diff --git a/contrib/dolphin/expected/builtin_funcs/b_compatibility_time_funcs.out b/contrib/dolphin/expected/builtin_funcs/b_compatibility_time_funcs.out index 148113232..5767c82b9 100644 --- a/contrib/dolphin/expected/builtin_funcs/b_compatibility_time_funcs.out +++ b/contrib/dolphin/expected/builtin_funcs/b_compatibility_time_funcs.out @@ -585,6 +585,127 @@ CONTEXT: referenced column: hour 0 (1 row) +-- date_bool&time_bool +select date_bool('0000-00-00'); + date_bool +----------- + f +(1 row) + +select time_bool('00:00:00'); + time_bool +----------- + f +(1 row) + +select date_bool('0000-00-01'); +WARNING: date/time field value out of range: "0000-00-01" +LINE 1: select date_bool('0000-00-01'); + ^ +CONTEXT: referenced column: date_bool + date_bool +----------- + f +(1 row) + +select time_bool('00:00:01'); + time_bool +----------- + t +(1 row) + +select date_bool('0000-01-00'); +WARNING: date/time field value out of range: "0000-01-00" +LINE 1: select date_bool('0000-01-00'); + ^ +CONTEXT: referenced column: date_bool + date_bool +----------- + f +(1 row) + +select time_bool('00:01:00'); + time_bool +----------- + t +(1 row) + +select date_bool('0000-01-01'); + date_bool +----------- + t +(1 row) + +select time_bool('00:01:01'); + time_bool +----------- + t +(1 row) + +select date_bool('0001-00-00'); +WARNING: date/time field value out of range: "0001-00-00" +LINE 1: select date_bool('0001-00-00'); + ^ +CONTEXT: referenced column: date_bool + date_bool +----------- + f +(1 row) + +select time_bool('01:00:00'); + time_bool +----------- + t +(1 row) + +select date_bool('0001-00-01'); + date_bool +----------- + t +(1 row) + +select time_bool('01:00:01'); + time_bool +----------- + t +(1 row) + +select date_bool('0001-01-00'); + date_bool +----------- + t +(1 row) + +select time_bool('01:01:00'); + time_bool +----------- + t +(1 row) + +select date_bool('2020-12-31'); + date_bool +----------- + t +(1 row) + +select date_bool('2020-12-31 BC'); + date_bool +----------- + t +(1 row) + +select time_bool('838:59:59'); + time_bool +----------- + t +(1 row) + +select time_bool('-838:59:59'); + time_bool +----------- + t +(1 row) + reset dolphin.sql_mode; drop schema b_time_funcs cascade; NOTICE: drop cascades to table func_test diff --git a/contrib/dolphin/plugin_utils/adt/date.cpp b/contrib/dolphin/plugin_utils/adt/date.cpp index 811bd4b90..764252ac6 100644 --- a/contrib/dolphin/plugin_utils/adt/date.cpp +++ b/contrib/dolphin/plugin_utils/adt/date.cpp @@ -4794,10 +4794,10 @@ Datum date_bool(PG_FUNCTION_ARGS) timestamp = date2timestamp(dateVal); if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) == 0) { - if (tm->tm_year > 0 || tm->tm_mon > 0 || tm->tm_mday > 0) - PG_RETURN_BOOL(true); + if (tm->tm_year == 0 && tm->tm_mon == 0 && tm->tm_mday == 0) + PG_RETURN_BOOL(false); else - PG_RETURN_NULL(); + PG_RETURN_BOOL(true); } else { ereport(ERROR, (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), errmsg("timestamp out of range"))); } @@ -4814,10 +4814,10 @@ Datum time_bool(PG_FUNCTION_ARGS) struct pg_tm tt, *tm = &tt; if (time2tm(timeVal, tm, &fsec) == 0) { - if (tm->tm_hour > 0 || tm->tm_min > 0 || tm->tm_sec > 0) - PG_RETURN_BOOL(true); - else + if (tm->tm_hour == 0 && tm->tm_min == 0 && tm->tm_sec == 0) PG_RETURN_BOOL(false); + else + PG_RETURN_BOOL(true); } else { ereport(ERROR, (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), errmsg("time out of range"))); } diff --git a/contrib/dolphin/sql/builtin_funcs/b_compatibility_time_funcs.sql b/contrib/dolphin/sql/builtin_funcs/b_compatibility_time_funcs.sql index cd67c4078..6e46af2d0 100644 --- a/contrib/dolphin/sql/builtin_funcs/b_compatibility_time_funcs.sql +++ b/contrib/dolphin/sql/builtin_funcs/b_compatibility_time_funcs.sql @@ -260,6 +260,26 @@ select hour(''); select hour('abc'); select hour('1234abc'); +-- date_bool&time_bool +select date_bool('0000-00-00'); +select time_bool('00:00:00'); +select date_bool('0000-00-01'); +select time_bool('00:00:01'); +select date_bool('0000-01-00'); +select time_bool('00:01:00'); +select date_bool('0000-01-01'); +select time_bool('00:01:01'); +select date_bool('0001-00-00'); +select time_bool('01:00:00'); +select date_bool('0001-00-01'); +select time_bool('01:00:01'); +select date_bool('0001-01-00'); +select time_bool('01:01:00'); +select date_bool('2020-12-31'); +select date_bool('2020-12-31 BC'); +select time_bool('838:59:59'); +select time_bool('-838:59:59'); + reset dolphin.sql_mode; drop schema b_time_funcs cascade; -- Gitee