From 744c822d8637fe69c68de80b538421be45c93d07 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Tue, 8 Feb 2022 14:29:41 +0800 Subject: [PATCH] [TD-11220](query): time related functions --- src/client/src/tscParseInsert.c | 6 +++++- src/util/src/ttokenizer.c | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index 73337469b2..c5719dde27 100644 --- a/src/client/src/tscParseInsert.c +++ b/src/client/src/tscParseInsert.c @@ -70,6 +70,10 @@ int tsParseTime(SStrToken *pToken, int64_t *time, char **next, char *error, int1 if (pToken->type == TK_NOW) { useconds = taosGetTimestamp(timePrec); + } else if (pToken->type == TK_TODAY) { + int64_t factor = (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 : + (timePrec == TSDB_TIME_PRECISION_MICRO) ? 1000000 : 1000000000; + useconds = taosGetTimestampToday() * factor; } else if (strncmp(pToken->z, "0", 1) == 0 && pToken->n == 1) { // do nothing } else if (pToken->type == TK_INTEGER) { @@ -473,7 +477,7 @@ int tsParseOneRow(char **str, STableDataBlocks *pDataBlocks, int16_t timePrec, i } int16_t type = sToken.type; - if ((type != TK_NOW && type != TK_INTEGER && type != TK_STRING && type != TK_FLOAT && type != TK_BOOL && + if ((type != TK_NOW && type != TK_TODAY && type != TK_INTEGER && type != TK_STRING && type != TK_FLOAT && type != TK_BOOL && type != TK_NULL && type != TK_HEX && type != TK_OCT && type != TK_BIN) || (sToken.n == 0) || (type == TK_RP)) { return tscSQLSyntaxErrMsg(pInsertParam->msg, "invalid data or symbol", sToken.z); diff --git a/src/util/src/ttokenizer.c b/src/util/src/ttokenizer.c index 8b97912984..a480fa5d6a 100644 --- a/src/util/src/ttokenizer.c +++ b/src/util/src/ttokenizer.c @@ -667,8 +667,9 @@ SStrToken tStrGetToken(char* str, int32_t* i, bool isPrevOptr) { #endif } - //for now() function used in insert clause - if (t0.type == TK_NOW && str[t0.n] == '(' && str[t0.n + 1] == ')') { + //for now(),today() function used in insert clause + if ((t0.type == TK_NOW || t0.type == TK_TODAY) && + str[t0.n] == '(' && str[t0.n + 1] == ')') { t0.n += 2; } -- GitLab