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 1481132321fe7bd9f9292f8de5c0d9112c2bee8c..5767c82b9acb4d9e0d955c2078c84ea49be44398 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 811bd4b90a242f48fa1f7309c215f17967cd3368..764252ac611247790f3b8c2bc2069c9ecf41db6c 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 cd67c40785615e17e3f7ab6b06664cf341040eae..6e46af2d090b1a6d93ef454546bcca3023c88a6f 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;