From b8c4ac6de15a26f0c20ea55feb2a078836900bca Mon Sep 17 00:00:00 2001 From: Satarupa Biswas Date: Mon, 10 Apr 2023 08:32:15 +0000 Subject: [PATCH] CASTing a DATE literal without time part to TIME datatype fails For time datatype PG considers only date value(ex.- '2012-02-23') as bad i/p format. so, above testcase is throwing error from engine code time_in() much before coming to TDS side. However, SQL Server allows casting a date literal string to a TIME datatype when the time component in the string is missing: o/p becomes 00:00:00.0000000 Fix is to add change in time_in() so that it considers date format with missing time info like above one, as valid input when the dialect is TSQL. Task: BABEL-1528 Signed-off-by: Satarupa Biswas satarupb@amazon.com --- src/backend/utils/adt/datetime.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c index a3cfd54409b..226fc80d297 100644 --- a/src/backend/utils/adt/datetime.c +++ b/src/backend/utils/adt/datetime.c @@ -31,6 +31,7 @@ #include "utils/datetime.h" #include "utils/memutils.h" #include "utils/tzparser.h" +#include "parser/parser.h" static int DecodeNumber(int flen, char *field, bool haveTextMonth, int fmask, int *tmask, @@ -1972,6 +1973,12 @@ DecodeTimeOnly(char **field, int *ftype, int nf, if (dterr) return dterr; } + /* + * For date format like 'yyyy-mm-dd', we should return time 00:00:00.0000000 + * instead of marking it as invalid time format + */ + else if (sql_dialect == SQL_DIALECT_TSQL && nf == 1 && ftype[nf - 1] == DTK_DATE) + return 0; /* otherwise, this is a time and/or time zone */ else {