Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CASTing a DATE literal without time part to TIME datatype fails #125

Open
wants to merge 1 commit into
base: BABEL_3_X_DEV__PG_15_X
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/backend/utils/adt/datetime.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nf = numField (parsed and calculated based on delimiter ' ' and . in any input date)
Ex.
'08-04-1978 13:56:32.125431' has nf count = 3 (08-04-1978, 13:56:32, 125431)
'08-04-1978 13:56:32' has nf count = 2 (08-04-1978, 13:56:32)
'08-04-1978' has nf count = 1 (08-04-1978)

else
{
Expand Down