LCOV - code coverage report
Current view: top level - monetdb5/modules/atoms - mtime.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 249 289 86.2 %
Date: 2024-04-26 00:35:57 Functions: 162 330 49.1 %

          Line data    Source code
       1             : /*
       2             :  * SPDX-License-Identifier: MPL-2.0
       3             :  *
       4             :  * This Source Code Form is subject to the terms of the Mozilla Public
       5             :  * License, v. 2.0.  If a copy of the MPL was not distributed with this
       6             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       7             :  *
       8             :  * Copyright 2024 MonetDB Foundation;
       9             :  * Copyright August 2008 - 2023 MonetDB B.V.;
      10             :  * Copyright 1997 - July 2008 CWI.
      11             :  */
      12             : 
      13             : /* In this file we implement three new types with supporting code.
      14             :  * The types are:
      15             :  *
      16             :  * - daytime - representing a time-of-day between 00:00:00 (included)
      17             :  *   and 24:00:00 (not included);
      18             :  * - date - representing a date between the year -4712 and 170050;
      19             :  * - timestamp - a combination of date and daytime, representing an
      20             :  *   exact point in time.
      21             :  *
      22             :  * Dates, both in the date and the timestamp types, are represented in
      23             :  * the so-called proleptic Gregorian calendar, that is to say, the
      24             :  * Gregorian calendar (which is in common use today) is extended
      25             :  * backwards.  See e.g.
      26             :  * <https://en.wikipedia.org/wiki/Proleptic_Gregorian_calendar>.
      27             :  *
      28             :  * Times, both in the daytime and the timestamp types, are recorded
      29             :  * with microsecond precision.
      30             :  *
      31             :  * Times and timestamps are all in UTC.  Conversion from the system
      32             :  * time zone where appropriate is done automatically.
      33             :  */
      34             : 
      35             : #include "monetdb_config.h"
      36             : #include "mtime.h"
      37             : #include "mal_client.h"
      38             : 
      39             : 
      40             : #ifndef HAVE_STRPTIME
      41             : extern char *strptime(const char *, const char *, struct tm *);
      42             : #endif
      43             : 
      44             : /* interfaces callable from MAL, not used from any C code */
      45             : 
      46             : static str
      47          22 : MTIMEcurrent_date(date *ret)
      48             : {
      49          22 :         *ret = timestamp_date(timestamp_current());
      50          22 :         return MAL_SUCCEED;
      51             : }
      52             : 
      53             : static str
      54           9 : MTIMEcurrent_time(daytime *ret)
      55             : {
      56           9 :         *ret = timestamp_daytime(timestamp_current());
      57           9 :         return MAL_SUCCEED;
      58             : }
      59             : 
      60             : static str
      61          59 : MTIMEcurrent_timestamp(timestamp *ret)
      62             : {
      63          59 :         *ret = timestamp_current();
      64          59 :         return MAL_SUCCEED;
      65             : }
      66             : 
      67             : #define is_str_nil strNil
      68             : 
      69             : #define MTIME_STR_BUFFER_LENGTH MAX(strlen(str_nil) + 1, 512)
      70             : 
      71             : 
      72             : #define DEC_VAR_R(TYPE, ARG) TYPE *restrict ptr##ARG
      73             : 
      74             : #define DEC_VAR(TYPE, ARG) TYPE *ptr##ARG
      75             : 
      76             : #define DEC_ITER(TYPE, ARG)
      77             : 
      78             : #define DEC_BUFFER(OUTTYPE, RES, MALFUNC) \
      79             :         OUTTYPE RES = GDKmalloc(MTIME_STR_BUFFER_LENGTH); \
      80             :         if (!res) {     \
      81             :                 msg = createException(MAL, "batmtime." MALFUNC, SQLSTATE(HY013) MAL_MALLOC_FAIL); \
      82             :                 goto bailout; \
      83             :         }
      84             : 
      85             : #define DEC_INT(OUTTYPE, RES, MALFUNC) OUTTYPE RES = (OUTTYPE){0}
      86             : 
      87             : #define INIT_VAROUT(ARG) ptr##ARG = Tloc(b##ARG, 0)
      88             : #define INIT_VARIN(ARG) ptr##ARG = b##ARG##i.base
      89             : #define INIT_ITERIN(ARG)
      90             : 
      91             : #define APPEND_VAR(MALFUNC) ptrn[i] = res
      92             : 
      93             : #define GET_NEXT_VAR(ARG, OFF) ptr##ARG[OFF]
      94             : 
      95             : #define APPEND_STR(MALFUNC) \
      96             :         if (tfastins_nocheckVAR(bn, i, res) != GDK_SUCCEED) { \
      97             :                 msg = createException(SQL, "batmtime." MALFUNC, SQLSTATE(HY013) MAL_MALLOC_FAIL); \
      98             :                 break; \
      99             :         }
     100             : 
     101             : #define GET_NEXT_ITER(ARG, OFF) BUNtvar(b##ARG##i, OFF)
     102             : 
     103             : #define DEC_NOTHING(TYPE, ARG)
     104             : #define INIT_NOTHING(ARG)
     105             : 
     106             : #define FINISH_BUFFER_SINGLE(MALFUNC) \
     107             : bailout: \
     108             :         *ret = NULL; \
     109             :         if (!msg && res && !(*ret = GDKstrdup(res))) \
     110             :                 msg = createException(MAL, "batmtime." MALFUNC, SQLSTATE(HY013) MAL_MALLOC_FAIL); \
     111             :         GDKfree(res)
     112             : 
     113             : #define FINISH_INT_SINGLE(MALFUNC) *ret = res
     114             : 
     115             : #define FINISH_BUFFER_MULTI(RES) GDKfree(RES)
     116             : 
     117             : #define CLEAR_NOTHING(RES)
     118             : 
     119             : 
     120             : #define COPYFLAGS(n)    do { bn->tsorted = b1i.sorted; bn->trevsorted = b1i.revsorted; } while (0)
     121             : #define SETFLAGS(n)     do { bn->tsorted = bn->trevsorted = n < 2; } while (0)
     122             : #define func1(NAME, MALFUNC, INTYPE, OUTTYPE,                                                   \
     123             :                           FUNC, SETFLAGS, FUNC_CALL,                                                            \
     124             :                           DEC_SRC, DEC_OUTPUT,                                                                          \
     125             :                           INIT_SRC, INIT_OUTPUT, GET_NEXT_SRC)                                          \
     126             : static str                                                                                                                              \
     127             : NAME(OUTTYPE *ret, const INTYPE *src)                                                                   \
     128             : {                                                                                                                                               \
     129             :         str msg = MAL_SUCCEED;                                                                                          \
     130             :         do {                                                                                                                            \
     131             :                 FUNC_CALL(FUNC, (*ret), *src);                                                                  \
     132             :         } while (0);                                                                                                            \
     133             :         return msg;                                                                                                                     \
     134             : }                                                                                                                                               \
     135             : static str                                                                                                                              \
     136             : NAME##_bulk(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)    \
     137             : {                                                                                                                                               \
     138             :         str msg = MAL_SUCCEED;                                                                                          \
     139             :         BAT *b1 = NULL, *s = NULL, *bn = NULL;                                                          \
     140             :         struct canditer ci = {0};                                                                                       \
     141             :         oid off;                                                                                                                        \
     142             :         bool nils = false;                                                                                                      \
     143             :         bat *ret = getArgReference_bat(stk, pci, 0),                                            \
     144             :                 *bid = getArgReference_bat(stk, pci, 1),                                                \
     145             :                 *sid = pci->argc == 3 ? getArgReference_bat(stk, pci, 2) : NULL; \
     146             :         BATiter b1i;                                                                                                            \
     147             :         DEC_SRC(INTYPE, 1);                                                                                                     \
     148             :         DEC_OUTPUT(OUTTYPE, n);                                                                                         \
     149             :                                                                                                                                                 \
     150             :         (void) cntxt;                                                                                                           \
     151             :         (void) mb;                                                                                                                      \
     152             :         if ((b1 = BATdescriptor(*bid)) == NULL) {                                                       \
     153             :                 msg = createException(MAL, "batmtime." MALFUNC,                                       \
     154             :                           SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);                                      \
     155             :                 goto bailout;                                                                                                   \
     156             :         }                                                                                                                                       \
     157             :         b1i = bat_iterator(b1);                                                                                         \
     158             :         if (sid && !is_bat_nil(*sid) && (s = BATdescriptor(*sid)) == NULL) { \
     159             :                 msg = createException(MAL, "batmtime." MALFUNC,                                       \
     160             :                           SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);                                      \
     161             :                 goto bailout;                                                                                                   \
     162             :         }                                                                                                                                       \
     163             :         off = b1->hseqbase;                                                                                                  \
     164             :         canditer_init(&ci, b1, s);                                                                                  \
     165             :         if ((bn = COLnew(ci.hseq, TYPE_##OUTTYPE, ci.ncand, TRANSIENT)) == NULL) { \
     166             :                 msg = createException(MAL, "batmtime." MALFUNC,                                       \
     167             :                           SQLSTATE(HY013) MAL_MALLOC_FAIL);                                                     \
     168             :                 goto bailout;                                                                                                   \
     169             :         }                                                                                                                                       \
     170             :         INIT_SRC(1);                                                                                                            \
     171             :         INIT_OUTPUT(n);                                                                                                         \
     172             :         if (ci.tpe == cand_dense) {                                                                                     \
     173             :                 for (BUN i = 0; i < ci.ncand; i++) {                                                 \
     174             :                         oid p = (canditer_next_dense(&ci) - off);                                   \
     175             :                         FUNC_CALL(FUNC, ptrn[i], GET_NEXT_SRC(1, p));                           \
     176             :                         nils |= is_##OUTTYPE##_nil(ptrn[i]);                                            \
     177             :                 }                                                                                                                               \
     178             :         } else {                                                                                                                        \
     179             :                 for (BUN i = 0; i < ci.ncand; i++) {                                                 \
     180             :                         oid p = (canditer_next(&ci) - off);                                                 \
     181             :                         FUNC_CALL(FUNC, ptrn[i], GET_NEXT_SRC(1, p));                           \
     182             :                         nils |= is_##OUTTYPE##_nil(ptrn[i]);                                            \
     183             :                 }                                                                                                                               \
     184             :         }                                                                                                                                       \
     185             :         BATsetcount(bn, ci.ncand);                                                                                      \
     186             :         bn->tnonil = !nils;                                                                                                  \
     187             :         bn->tnil = nils;                                                                                                     \
     188             :         bn->tkey = ci.ncand < 2;                                                                                  \
     189             :         SETFLAGS(ci.ncand);                                                                                                     \
     190             : bailout:                                                                                                                                \
     191             :         if (b1) {                                                                                                                       \
     192             :                 bat_iterator_end(&b1i);                                                                                     \
     193             :                 BBPunfix(b1->batCacheid);                                                                            \
     194             :         }                                                                                                                                       \
     195             :         BBPreclaim(s);                                                                                                          \
     196             :         if (bn) {                                                                                                                       \
     197             :                 if (msg)                                                                                                                \
     198             :                         BBPreclaim(bn);                                                                                         \
     199             :                 else {                                                                                                                  \
     200             :                         *ret = bn->batCacheid;                                                                               \
     201             :                         BBPkeepref(bn);                                                                                         \
     202             :                 }                                                                                                                               \
     203             :         }                                                                                                                                       \
     204             :         return msg;                                                                                                                     \
     205             : }
     206             : 
     207             : #define func1_noexcept(FUNC, RET, PARAM) RET = FUNC(PARAM)
     208             : #define func1_except(FUNC, RET, PARAM) msg = FUNC(&RET, PARAM); if (msg) break
     209             : 
     210             : #define func2(NAME, MALFUNC,                                                                                    \
     211             :                           INTYPE1, INTYPE2, OUTTYPE, FUNC, FUNC_CALL,                           \
     212             :                           DEC_SRC1, DEC_SRC2, DEC_OUTPUT, DEC_EXTRA,                            \
     213             :                           INIT_SRC1, INIT_SRC2, INIT_OUTPUT,                                            \
     214             :                           GET_NEXT_SRC1, GET_NEXT_SRC2,                                                         \
     215             :                           APPEND_NEXT, CLEAR_EXTRA_SINGLE, CLEAR_EXTRA_MULTI)           \
     216             : static str                                                                                                                              \
     217             : NAME(OUTTYPE *ret, const INTYPE1 *v1, const INTYPE2 *v2)                                \
     218             : {                                                                                                                                               \
     219             :         str msg = MAL_SUCCEED;                                                                                          \
     220             :         DEC_EXTRA(OUTTYPE, res, MALFUNC);                                                                       \
     221             :                                                                                                                                                 \
     222             :         do {                                                                                                                            \
     223             :                 FUNC_CALL(FUNC, res, *v1, *v2);                                                                 \
     224             :         } while (0);                                                                                                            \
     225             :         CLEAR_EXTRA_SINGLE(MALFUNC);                                                                            \
     226             :         return msg;                                                                                                                     \
     227             : }                                                                                                                                               \
     228             : static str                                                                                                                              \
     229             : NAME##_bulk(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)    \
     230             : {                                                                                                                                               \
     231             :         str msg = MAL_SUCCEED;                                                                                          \
     232             :         BAT *b1 = NULL, *b2 = NULL, *s1 = NULL, *s2 = NULL, *bn = NULL;         \
     233             :         oid off1, off2;                                                                                                         \
     234             :         struct canditer ci1 = {0}, ci2 = {0};                                                           \
     235             :         bool nils = false;                                                                                                      \
     236             :         bat *ret = getArgReference_bat(stk, pci, 0),                                            \
     237             :                 *bid1 = getArgReference_bat(stk, pci, 1),                                               \
     238             :                 *bid2 = getArgReference_bat(stk, pci, 2),                                               \
     239             :                 *sid1 = pci->argc == 5 ? getArgReference_bat(stk, pci, 3) : NULL, \
     240             :                 *sid2 = pci->argc == 5 ? getArgReference_bat(stk, pci, 4) : NULL; \
     241             :         BATiter b1i, b2i = (BATiter){ .vh = NULL };                                                     \
     242             :         DEC_SRC1(INTYPE1, 1);                                                                                           \
     243             :         DEC_SRC2(INTYPE2, 2);                                                                                           \
     244             :         DEC_OUTPUT(OUTTYPE, n);                                                                                         \
     245             :                                                                                                                                                 \
     246             :         (void) cntxt;                                                                                                           \
     247             :         (void) mb;                                                                                                                      \
     248             :         b1 = BATdescriptor(*bid1);                                                                                      \
     249             :         b2 = BATdescriptor(*bid2);                                                                                      \
     250             :         b1i = bat_iterator(b1);                                                                                         \
     251             :         b2i = bat_iterator(b2);                                                                                         \
     252             :         DEC_EXTRA(OUTTYPE, res, MALFUNC);                                                                       \
     253             :         if (b1 == NULL || b2 == NULL) {                                                                         \
     254             :                 msg = createException(MAL, "batmtime." MALFUNC,                                       \
     255             :                           SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);                                      \
     256             :                 goto bailout;                                                                                                   \
     257             :         }                                                                                                                                       \
     258             :         if (sid1 && !is_bat_nil(*sid1) && (s1 = BATdescriptor(*sid1)) == NULL) { \
     259             :                 msg = createException(MAL, "batmtime." MALFUNC,                                       \
     260             :                           SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);                                      \
     261             :                 goto bailout;                                                                                                   \
     262             :         }                                                                                                                                       \
     263             :         if (sid2 && !is_bat_nil(*sid2) && (s2 = BATdescriptor(*sid2)) == NULL) { \
     264             :                 msg = createException(MAL, "batmtime." MALFUNC,                                       \
     265             :                           SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);                                      \
     266             :                 goto bailout;                                                                                                   \
     267             :         }                                                                                                                                       \
     268             :         canditer_init(&ci1, b1, s1);                                                                                \
     269             :         canditer_init(&ci2, b2, s2);                                                                                \
     270             :         if (ci2.ncand != ci1.ncand || ci1.hseq != ci2.hseq) {                           \
     271             :                 msg = createException(MAL, "batmtime." MALFUNC,                                       \
     272             :                           "inputs not the same size");                                                                \
     273             :                 goto bailout;                                                                                                   \
     274             :         }                                                                                                                                       \
     275             :         if ((bn = COLnew(ci1.hseq, TYPE_##OUTTYPE, ci1.ncand, TRANSIENT)) == NULL) { \
     276             :                 msg = createException(MAL, "batmtime." MALFUNC,                                       \
     277             :                           SQLSTATE(HY013) MAL_MALLOC_FAIL);                                                     \
     278             :                 goto bailout;                                                                                                   \
     279             :         }                                                                                                                                       \
     280             :         off1 = b1->hseqbase;                                                                                         \
     281             :         off2 = b2->hseqbase;                                                                                         \
     282             :         INIT_SRC1(1);                                                                                                           \
     283             :         INIT_SRC2(2);                                                                                                           \
     284             :         INIT_OUTPUT(n);                                                                                                         \
     285             :         if (ci1.tpe == cand_dense && ci2.tpe == cand_dense) {                           \
     286             :                 for (BUN i = 0; i < ci1.ncand; i++) {                                                        \
     287             :                         oid p1 = (canditer_next_dense(&ci1) - off1);                                \
     288             :                         oid p2 = (canditer_next_dense(&ci2) - off2);                                \
     289             :                         FUNC_CALL(FUNC, res, GET_NEXT_SRC1(1, p1), GET_NEXT_SRC2(2, p2)); \
     290             :                         APPEND_NEXT(MALFUNC);                                                                           \
     291             :                         nils |= is_##OUTTYPE##_nil(res);                                                        \
     292             :                 }                                                                                                                               \
     293             :         } else {                                                                                                                        \
     294             :                 for (BUN i = 0; i < ci1.ncand; i++) {                                                        \
     295             :                         oid p1 = (canditer_next(&ci1) - off1);                                              \
     296             :                         oid p2 = (canditer_next(&ci2) - off2);                                              \
     297             :                         FUNC_CALL(FUNC, res, GET_NEXT_SRC1(1, p1), GET_NEXT_SRC2(2, p2)); \
     298             :                         APPEND_NEXT(MALFUNC);                                                                           \
     299             :                         nils |= is_##OUTTYPE##_nil(res);                                                        \
     300             :                 }                                                                                                                               \
     301             :         }                                                                                                                                       \
     302             :         BATsetcount(bn, ci1.ncand);                                                                                     \
     303             :         bn->tnonil = !nils;                                                                                                  \
     304             :         bn->tnil = nils;                                                                                                     \
     305             :         bn->tsorted = ci1.ncand < 2;                                                                              \
     306             :         bn->trevsorted = ci1.ncand < 2;                                                                           \
     307             :         bn->tkey = ci1.ncand < 2;                                                                                 \
     308             : bailout:                                                                                                                                \
     309             :         CLEAR_EXTRA_MULTI(res);                                                                                         \
     310             :         bat_iterator_end(&b1i);                                                                                             \
     311             :         bat_iterator_end(&b2i);                                                                                             \
     312             :         BBPreclaim(b1);                                                                                                         \
     313             :         BBPreclaim(b2);                                                                                                         \
     314             :         BBPreclaim(s1);                                                                                                         \
     315             :         BBPreclaim(s2);                                                                                                         \
     316             :         if (bn) {                                                                                                                       \
     317             :                 if (msg)                                                                                                                \
     318             :                         BBPreclaim(bn);                                                                                         \
     319             :                 else {                                                                                                                  \
     320             :                         *ret = bn->batCacheid;                                                                               \
     321             :                         BBPkeepref(bn);                                                                                         \
     322             :                 }                                                                                                                               \
     323             :         }                                                                                                                                       \
     324             :         return msg;                                                                                                                     \
     325             : }                                                                                                                                               \
     326             : static str                                                                                                                              \
     327             : NAME##_bulk_p1(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) \
     328             : {                                                                                                                                               \
     329             :         str msg = MAL_SUCCEED;                                                                                          \
     330             :         BAT *b2 = NULL, *s2 = NULL, *bn = NULL;                                                         \
     331             :         oid off2;                                                                                                                       \
     332             :         struct canditer ci2 = {0};                                                                                      \
     333             :         bool nils = false;                                                                                                      \
     334             :         bat *ret = getArgReference_bat(stk, pci, 0),                                            \
     335             :                 *bid2 = getArgReference_bat(stk, pci, 2),                                               \
     336             :                 *sid2 = pci->argc == 4 ? getArgReference_bat(stk, pci, 3) : NULL; \
     337             :         const INTYPE1 src1 = *(INTYPE1*)getArgReference(stk, pci, 1);           \
     338             :         BATiter b2i;                                                                                                            \
     339             :         DEC_SRC2(INTYPE2, 2);                                                                                           \
     340             :         DEC_OUTPUT(OUTTYPE, n);                                                                                         \
     341             :         DEC_EXTRA(OUTTYPE, res, MALFUNC);                                                                       \
     342             :                                                                                                                                                 \
     343             :         (void) cntxt;                                                                                                           \
     344             :         (void) mb;                                                                                                                      \
     345             :         if ((b2 = BATdescriptor(*bid2)) == NULL) {                                                      \
     346             :                 throw(MAL, "batmtime." MALFUNC,                                                                       \
     347             :                           SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);                                      \
     348             :         }                                                                                                                                       \
     349             :         b2i = bat_iterator(b2);                                                                                         \
     350             :         if (sid2 && !is_bat_nil(*sid2) && (s2 = BATdescriptor(*sid2)) == NULL) { \
     351             :                 msg = createException(MAL, "batmtime." MALFUNC,                                       \
     352             :                           SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);                                      \
     353             :                 goto bailout;                                                                                                   \
     354             :         }                                                                                                                                       \
     355             :         canditer_init(&ci2, b2, s2);                                                                                \
     356             :         if ((bn = COLnew(ci2.hseq, TYPE_##OUTTYPE, ci2.ncand, TRANSIENT)) == NULL) { \
     357             :                 msg = createException(MAL, "batmtime." MALFUNC,                                       \
     358             :                           SQLSTATE(HY013) MAL_MALLOC_FAIL);                                                     \
     359             :                 goto bailout;                                                                                                   \
     360             :         }                                                                                                                                       \
     361             :         off2 = b2->hseqbase;                                                                                         \
     362             :         INIT_SRC2(2);                                                                                                           \
     363             :         INIT_OUTPUT(n);                                                                                                         \
     364             :         if (ci2.tpe == cand_dense) {                                                                            \
     365             :                 for (BUN i = 0; i < ci2.ncand; i++) {                                                        \
     366             :                         oid p2 = (canditer_next_dense(&ci2) - off2);                                \
     367             :                         FUNC_CALL(FUNC, res, src1, GET_NEXT_SRC2(2, p2));                       \
     368             :                         APPEND_NEXT(MALFUNC);                                                                           \
     369             :                         nils |= is_##OUTTYPE##_nil(res);                                                        \
     370             :                 }                                                                                                                               \
     371             :         } else {                                                                                                                        \
     372             :                 for (BUN i = 0; i < ci2.ncand; i++) {                                                        \
     373             :                         oid p2 = (canditer_next(&ci2) - off2);                                              \
     374             :                         FUNC_CALL(FUNC, res, src1, GET_NEXT_SRC2(2, p2));                       \
     375             :                         APPEND_NEXT(MALFUNC);                                                                           \
     376             :                         nils |= is_##OUTTYPE##_nil(res);                                                        \
     377             :                 }                                                                                                                               \
     378             :         }                                                                                                                                       \
     379             :         BATsetcount(bn, ci2.ncand);                                                                                     \
     380             :         bn->tnonil = !nils;                                                                                                  \
     381             :         bn->tnil = nils;                                                                                                     \
     382             :         bn->tsorted = ci2.ncand < 2;                                                                              \
     383             :         bn->trevsorted = ci2.ncand < 2;                                                                           \
     384             :         bn->tkey = ci2.ncand < 2;                                                                                 \
     385             : bailout:                                                                                                                                \
     386             :         CLEAR_EXTRA_MULTI(res);                                                                                         \
     387             :         if (b2) {                                                                                                                       \
     388             :                 bat_iterator_end(&b2i);                                                                                     \
     389             :                 BBPunfix(b2->batCacheid);                                                                            \
     390             :         }                                                                                                                                       \
     391             :         BBPreclaim(s2);                                                                                                         \
     392             :         if (bn) {                                                                                                                       \
     393             :                 if (msg)                                                                                                                \
     394             :                         BBPreclaim(bn);                                                                                         \
     395             :                 else {                                                                                                                  \
     396             :                         *ret = bn->batCacheid;                                                                               \
     397             :                         BBPkeepref(bn);                                                                                         \
     398             :                 }                                                                                                                               \
     399             :         }                                                                                                                                       \
     400             :         return msg;                                                                                                                     \
     401             : }                                                                                                                                               \
     402             : static str                                                                                                                              \
     403             : NAME##_bulk_p2(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) \
     404             : {                                                                                                                                               \
     405             :         str msg = MAL_SUCCEED;                                                                                          \
     406             :         BAT *b1 = NULL, *s1 = NULL, *bn = NULL;                                                         \
     407             :         oid off1;                                                                                                                       \
     408             :         struct canditer ci1 = {0};                                                                                      \
     409             :         bool nils = false;                                                                                                      \
     410             :         bat *ret = getArgReference_bat(stk, pci, 0),                                            \
     411             :                 *bid1 = getArgReference_bat(stk, pci, 1),                                               \
     412             :                 *sid1 = pci->argc == 4 ? getArgReference_bat(stk, pci, 3) : NULL; \
     413             :         BATiter b1i;                                                                                                            \
     414             :         DEC_SRC1(INTYPE1, 1);                                                                                           \
     415             :         const INTYPE2 src2 = *(INTYPE2*)getArgReference(stk, pci, 2);           \
     416             :         DEC_OUTPUT(OUTTYPE, n);                                                                                         \
     417             :         DEC_EXTRA(OUTTYPE, res, MALFUNC);                                                                       \
     418             :                                                                                                                                                 \
     419             :         (void) cntxt;                                                                                                           \
     420             :         (void) mb;                                                                                                                      \
     421             :         if ((b1 = BATdescriptor(*bid1)) == NULL) {                                                      \
     422             :                 msg = createException(MAL, "batmtime." MALFUNC,                                       \
     423             :                           SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);                                      \
     424             :                 goto bailout;                                                                                                   \
     425             :         }                                                                                                                                       \
     426             :         b1i = bat_iterator(b1);                                                                                         \
     427             :         if (sid1 && !is_bat_nil(*sid1) && (s1 = BATdescriptor(*sid1)) == NULL) { \
     428             :                 msg = createException(MAL, "batmtime." MALFUNC,                                       \
     429             :                           SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);                                      \
     430             :                 goto bailout;                                                                                                   \
     431             :         }                                                                                                                                       \
     432             :         canditer_init(&ci1, b1, s1);                                                                                \
     433             :         if ((bn = COLnew(ci1.hseq, TYPE_##OUTTYPE, ci1.ncand, TRANSIENT)) == NULL) { \
     434             :                 msg = createException(MAL, "batmtime." MALFUNC,                                       \
     435             :                           SQLSTATE(HY013) MAL_MALLOC_FAIL);                                                     \
     436             :                 goto bailout;                                                                                                   \
     437             :         }                                                                                                                                       \
     438             :         off1 = b1->hseqbase;                                                                                         \
     439             :         INIT_SRC1(1);                                                                                                           \
     440             :         INIT_OUTPUT(n);                                                                                                         \
     441             :         if (ci1.tpe == cand_dense) {                                                                            \
     442             :                 for (BUN i = 0; i < ci1.ncand; i++) {                                                        \
     443             :                         oid p1 = (canditer_next_dense(&ci1) - off1);                                \
     444             :                         FUNC_CALL(FUNC, res, GET_NEXT_SRC1(1, p1), src2);                       \
     445             :                         APPEND_NEXT(MALFUNC);                                                                           \
     446             :                         nils |= is_##OUTTYPE##_nil(res);                                                        \
     447             :                 }                                                                                                                               \
     448             :         } else {                                                                                                                        \
     449             :                 for (BUN i = 0; i < ci1.ncand; i++) {                                                        \
     450             :                         oid p1 = (canditer_next(&ci1) - off1);                                              \
     451             :                         FUNC_CALL(FUNC, res, GET_NEXT_SRC1(1, p1), src2);                       \
     452             :                         APPEND_NEXT(MALFUNC);                                                                           \
     453             :                         nils |= is_##OUTTYPE##_nil(res);                                                        \
     454             :                 }                                                                                                                               \
     455             :         }                                                                                                                                       \
     456             :         BATsetcount(bn, ci1.ncand);                                                                                     \
     457             :         bn->tnonil = !nils;                                                                                                  \
     458             :         bn->tnil = nils;                                                                                                     \
     459             :         bn->tsorted = ci1.ncand < 2;                                                                              \
     460             :         bn->trevsorted = ci1.ncand < 2;                                                                           \
     461             :         bn->tkey = ci1.ncand < 2;                                                                                 \
     462             : bailout:                                                                                                                                \
     463             :         CLEAR_EXTRA_MULTI(res);                                                                                         \
     464             :         if (b1) {                                                                                                                       \
     465             :                 bat_iterator_end(&b1i);                                                                                     \
     466             :                 BBPunfix(b1->batCacheid);                                                                            \
     467             :         }                                                                                                                                       \
     468             :         BBPreclaim(s1);                                                                                                         \
     469             :         if (bn) {                                                                                                                       \
     470             :                 if (msg)                                                                                                                \
     471             :                         BBPreclaim(bn);                                                                                         \
     472             :                 else {                                                                                                                  \
     473             :                         *ret = bn->batCacheid;                                                                               \
     474             :                         BBPkeepref(bn);                                                                                         \
     475             :                 }                                                                                                                               \
     476             :         }                                                                                                                                       \
     477             :         return msg;                                                                                                                     \
     478             : }
     479             : 
     480             : #define func2_noexcept(FUNC, RET, PARAM1, PARAM2) RET = FUNC(PARAM1, PARAM2)
     481             : #define func2_except(FUNC, RET, PARAM1, PARAM2) msg = FUNC(&RET, PARAM1, PARAM2); if (msg) break
     482             : 
     483             : #define func3(NAME, MALFUNC,                                                                                    \
     484             :                           INTYPE1, INTYPE2, OUTTYPE, FUNC, FUNC_CALL,                           \
     485             :                           DEC_SRC1, DEC_SRC2, DEC_OUTPUT, DEC_EXTRA,                            \
     486             :                           INIT_SRC1, INIT_SRC2, INIT_OUTPUT,                                            \
     487             :                           GET_NEXT_SRC1, GET_NEXT_SRC2,                                                         \
     488             :                           APPEND_NEXT, CLEAR_EXTRA_SINGLE, CLEAR_EXTRA_MULTI)           \
     489             : static str                                                                                                                              \
     490             : NAME(OUTTYPE *ret, const INTYPE1 *v1, const INTYPE2 *v2, const lng *extra)                              \
     491             : {                                                                                                                                               \
     492             :         str msg = MAL_SUCCEED;                                                                                          \
     493             :         DEC_EXTRA(OUTTYPE, res, MALFUNC);                                                                       \
     494             :                                                                                                                                                 \
     495             :         do {                                                                                                                            \
     496             :                 FUNC_CALL(FUNC, res, *v1, *v2, *extra);                                                                 \
     497             :         } while (0);                                                                                                            \
     498             :         CLEAR_EXTRA_SINGLE(MALFUNC);                                                                            \
     499             :         return msg;                                                                                                                     \
     500             : }                                                                                                                                               \
     501             : static str                                                                                                                              \
     502             : NAME##_bulk(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)    \
     503             : {                                                                                                                                               \
     504             :         str msg = MAL_SUCCEED;                                                                                          \
     505             :         BAT *b1 = NULL, *b2 = NULL, *s1 = NULL, *s2 = NULL, *bn = NULL;         \
     506             :         oid off1, off2;                                                                                                         \
     507             :         struct canditer ci1 = {0}, ci2 = {0};                                                           \
     508             :         bool nils = false;                                                                                                      \
     509             :         bat *ret = getArgReference_bat(stk, pci, 0),                                            \
     510             :                 *bid1 = getArgReference_bat(stk, pci, 1),                                               \
     511             :                 *bid2 = getArgReference_bat(stk, pci, 2),                                               \
     512             :                 *sid1 = pci->argc == 6 ? getArgReference_bat(stk, pci, 3) : NULL, \
     513             :                 *sid2 = pci->argc == 6 ? getArgReference_bat(stk, pci, 4) : NULL; \
     514             :         lng *extra = getArgReference_lng(stk, pci, pci->argc-1);                                             \
     515             :         BATiter b1i, b2i = (BATiter){ .vh = NULL };                                                     \
     516             :         DEC_SRC1(INTYPE1, 1);                                                                                           \
     517             :         DEC_SRC2(INTYPE2, 2);                                                                                           \
     518             :         DEC_OUTPUT(OUTTYPE, n);                                                                                         \
     519             :                                                                                                                                                 \
     520             :         (void) cntxt;                                                                                                           \
     521             :         (void) mb;                                                                                                                      \
     522             :         b1 = BATdescriptor(*bid1);                                                                                      \
     523             :         b2 = BATdescriptor(*bid2);                                                                                      \
     524             :         b1i = bat_iterator(b1);                                                                                         \
     525             :         b2i = bat_iterator(b2);                                                                                         \
     526             :         DEC_EXTRA(OUTTYPE, res, MALFUNC);                                                                       \
     527             :         if (b1 == NULL || b2 == NULL) {                                                                         \
     528             :                 msg = createException(MAL, "batmtime." MALFUNC,                                       \
     529             :                           SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);                                      \
     530             :                 goto bailout;                                                                                                   \
     531             :         }                                                                                                                                       \
     532             :         if (sid1 && !is_bat_nil(*sid1) && (s1 = BATdescriptor(*sid1)) == NULL) { \
     533             :                 msg = createException(MAL, "batmtime." MALFUNC,                                       \
     534             :                           SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);                                      \
     535             :                 goto bailout;                                                                                                   \
     536             :         }                                                                                                                                       \
     537             :         if (sid2 && !is_bat_nil(*sid2) && (s2 = BATdescriptor(*sid2)) == NULL) { \
     538             :                 msg = createException(MAL, "batmtime." MALFUNC,                                       \
     539             :                           SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);                                      \
     540             :                 goto bailout;                                                                                                   \
     541             :         }                                                                                                                                       \
     542             :         canditer_init(&ci1, b1, s1);                                                                                \
     543             :         canditer_init(&ci2, b2, s2);                                                                                \
     544             :         if (ci2.ncand != ci1.ncand || ci1.hseq != ci2.hseq) {                           \
     545             :                 msg = createException(MAL, "batmtime." MALFUNC,                                       \
     546             :                           "inputs not the same size");                                                                \
     547             :                 goto bailout;                                                                                                   \
     548             :         }                                                                                                                                       \
     549             :         if ((bn = COLnew(ci1.hseq, TYPE_##OUTTYPE, ci1.ncand, TRANSIENT)) == NULL) { \
     550             :                 msg = createException(MAL, "batmtime." MALFUNC,                                       \
     551             :                           SQLSTATE(HY013) MAL_MALLOC_FAIL);                                                     \
     552             :                 goto bailout;                                                                                                   \
     553             :         }                                                                                                                                       \
     554             :         off1 = b1->hseqbase;                                                                                         \
     555             :         off2 = b2->hseqbase;                                                                                         \
     556             :         INIT_SRC1(1);                                                                                                           \
     557             :         INIT_SRC2(2);                                                                                                           \
     558             :         INIT_OUTPUT(n);                                                                                                         \
     559             :         if (ci1.tpe == cand_dense && ci2.tpe == cand_dense) {                           \
     560             :                 for (BUN i = 0; i < ci1.ncand; i++) {                                                        \
     561             :                         oid p1 = (canditer_next_dense(&ci1) - off1);                                \
     562             :                         oid p2 = (canditer_next_dense(&ci2) - off2);                                \
     563             :                         FUNC_CALL(FUNC, res, GET_NEXT_SRC1(1, p1), GET_NEXT_SRC2(2, p2), *extra); \
     564             :                         APPEND_NEXT(MALFUNC);                                                                           \
     565             :                         nils |= is_##OUTTYPE##_nil(res);                                                        \
     566             :                 }                                                                                                                               \
     567             :         } else {                                                                                                                        \
     568             :                 for (BUN i = 0; i < ci1.ncand; i++) {                                                        \
     569             :                         oid p1 = (canditer_next(&ci1) - off1);                                              \
     570             :                         oid p2 = (canditer_next(&ci2) - off2);                                              \
     571             :                         FUNC_CALL(FUNC, res, GET_NEXT_SRC1(1, p1), GET_NEXT_SRC2(2, p2), *extra); \
     572             :                         APPEND_NEXT(MALFUNC);                                                                           \
     573             :                         nils |= is_##OUTTYPE##_nil(res);                                                        \
     574             :                 }                                                                                                                               \
     575             :         }                                                                                                                                       \
     576             :         BATsetcount(bn, ci1.ncand);                                                                                     \
     577             :         bn->tnonil = !nils;                                                                                                  \
     578             :         bn->tnil = nils;                                                                                                     \
     579             :         bn->tsorted = ci1.ncand < 2;                                                                              \
     580             :         bn->trevsorted = ci1.ncand < 2;                                                                           \
     581             :         bn->tkey = ci1.ncand < 2;                                                                                 \
     582             : bailout:                                                                                                                                \
     583             :         CLEAR_EXTRA_MULTI(res);                                                                                         \
     584             :         bat_iterator_end(&b1i);                                                                                             \
     585             :         bat_iterator_end(&b2i);                                                                                             \
     586             :         BBPreclaim(b1);                                                                                                         \
     587             :         BBPreclaim(b2);                                                                                                         \
     588             :         BBPreclaim(s1);                                                                                                         \
     589             :         BBPreclaim(s2);                                                                                                         \
     590             :         if (bn) {                                                                                                                       \
     591             :                 if (msg)                                                                                                                \
     592             :                         BBPreclaim(bn);                                                                                         \
     593             :                 else {                                                                                                                  \
     594             :                         *ret = bn->batCacheid;                                                                               \
     595             :                         BBPkeepref(bn);                                                                                         \
     596             :                 }                                                                                                                               \
     597             :         }                                                                                                                                       \
     598             :         return msg;                                                                                                                     \
     599             : }                                                                                                                                               \
     600             : static str                                                                                                                              \
     601             : NAME##_bulk_p1(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) \
     602             : {                                                                                                                                               \
     603             :         str msg = MAL_SUCCEED;                                                                                          \
     604             :         BAT *b2 = NULL, *s2 = NULL, *bn = NULL;                                                         \
     605             :         oid off2;                                                                                                                       \
     606             :         struct canditer ci2 = {0};                                                                                      \
     607             :         bool nils = false;                                                                                                      \
     608             :         bat *ret = getArgReference_bat(stk, pci, 0),                                            \
     609             :                 *bid2 = getArgReference_bat(stk, pci, 2),                                               \
     610             :                 *sid2 = pci->argc == 5 ? getArgReference_bat(stk, pci, 3) : NULL; \
     611             :         lng *extra = getArgReference_lng(stk, pci, pci->argc-1);                                             \
     612             :         const INTYPE1 src1 = *(INTYPE1*)getArgReference(stk, pci, 1);           \
     613             :         BATiter b2i;                                                                                                            \
     614             :         DEC_SRC2(INTYPE2, 2);                                                                                           \
     615             :         DEC_OUTPUT(OUTTYPE, n);                                                                                         \
     616             :         DEC_EXTRA(OUTTYPE, res, MALFUNC);                                                                       \
     617             :                                                                                                                                                 \
     618             :         (void) cntxt;                                                                                                           \
     619             :         (void) mb;                                                                                                                      \
     620             :         if ((b2 = BATdescriptor(*bid2)) == NULL) {                                                      \
     621             :                 throw(MAL, "batmtime." MALFUNC,                                                                       \
     622             :                           SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);                                      \
     623             :         }                                                                                                                                       \
     624             :         b2i = bat_iterator(b2);                                                                                         \
     625             :         if (sid2 && !is_bat_nil(*sid2) && (s2 = BATdescriptor(*sid2)) == NULL) { \
     626             :                 msg = createException(MAL, "batmtime." MALFUNC,                                       \
     627             :                           SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);                                      \
     628             :                 goto bailout;                                                                                                   \
     629             :         }                                                                                                                                       \
     630             :         canditer_init(&ci2, b2, s2);                                                                                \
     631             :         if ((bn = COLnew(ci2.hseq, TYPE_##OUTTYPE, ci2.ncand, TRANSIENT)) == NULL) { \
     632             :                 msg = createException(MAL, "batmtime." MALFUNC,                                       \
     633             :                           SQLSTATE(HY013) MAL_MALLOC_FAIL);                                                     \
     634             :                 goto bailout;                                                                                                   \
     635             :         }                                                                                                                                       \
     636             :         off2 = b2->hseqbase;                                                                                         \
     637             :         INIT_SRC2(2);                                                                                                           \
     638             :         INIT_OUTPUT(n);                                                                                                         \
     639             :         if (ci2.tpe == cand_dense) {                                                                            \
     640             :                 for (BUN i = 0; i < ci2.ncand; i++) {                                                        \
     641             :                         oid p2 = (canditer_next_dense(&ci2) - off2);                                \
     642             :                         FUNC_CALL(FUNC, res, src1, GET_NEXT_SRC2(2, p2), *extra);       \
     643             :                         APPEND_NEXT(MALFUNC);                                                                           \
     644             :                         nils |= is_##OUTTYPE##_nil(res);                                                        \
     645             :                 }                                                                                                                               \
     646             :         } else {                                                                                                                        \
     647             :                 for (BUN i = 0; i < ci2.ncand; i++) {                                                        \
     648             :                         oid p2 = (canditer_next(&ci2) - off2);                                              \
     649             :                         FUNC_CALL(FUNC, res, src1, GET_NEXT_SRC2(2, p2), *extra);       \
     650             :                         APPEND_NEXT(MALFUNC);                                                                           \
     651             :                         nils |= is_##OUTTYPE##_nil(res);                                                        \
     652             :                 }                                                                                                                               \
     653             :         }                                                                                                                                       \
     654             :         BATsetcount(bn, ci2.ncand);                                                                                     \
     655             :         bn->tnonil = !nils;                                                                                                  \
     656             :         bn->tnil = nils;                                                                                                     \
     657             :         bn->tsorted = ci2.ncand < 2;                                                                              \
     658             :         bn->trevsorted = ci2.ncand < 2;                                                                           \
     659             :         bn->tkey = ci2.ncand < 2;                                                                                 \
     660             : bailout:                                                                                                                                \
     661             :         CLEAR_EXTRA_MULTI(res);                                                                                         \
     662             :         if (b2) {                                                                                                                       \
     663             :                 bat_iterator_end(&b2i);                                                                                     \
     664             :                 BBPunfix(b2->batCacheid);                                                                            \
     665             :         }                                                                                                                                       \
     666             :         BBPreclaim(s2);                                                                                                         \
     667             :         if (bn) {                                                                                                                       \
     668             :                 if (msg)                                                                                                                \
     669             :                         BBPreclaim(bn);                                                                                         \
     670             :                 else {                                                                                                                  \
     671             :                         *ret = bn->batCacheid;                                                                               \
     672             :                         BBPkeepref(bn);                                                                                         \
     673             :                 }                                                                                                                               \
     674             :         }                                                                                                                                       \
     675             :         return msg;                                                                                                                     \
     676             : }                                                                                                                                               \
     677             : static str                                                                                                                              \
     678             : NAME##_bulk_p2(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) \
     679             : {                                                                                                                                               \
     680             :         str msg = MAL_SUCCEED;                                                                                          \
     681             :         BAT *b1 = NULL, *s1 = NULL, *bn = NULL;                                                         \
     682             :         oid off1;                                                                                                                       \
     683             :         struct canditer ci1 = {0};                                                                                      \
     684             :         bool nils = false;                                                                                                      \
     685             :         bat *ret = getArgReference_bat(stk, pci, 0),                                            \
     686             :                 *bid1 = getArgReference_bat(stk, pci, 1),                                               \
     687             :                 *sid1 = pci->argc == 5 ? getArgReference_bat(stk, pci, 3) : NULL; \
     688             :         lng *extra = getArgReference_lng(stk, pci, pci->argc-1);                                             \
     689             :         BATiter b1i;                                                                                                            \
     690             :         DEC_SRC1(INTYPE1, 1);                                                                                           \
     691             :         const INTYPE2 src2 = *(INTYPE2*)getArgReference(stk, pci, 2);           \
     692             :         DEC_OUTPUT(OUTTYPE, n);                                                                                         \
     693             :         DEC_EXTRA(OUTTYPE, res, MALFUNC);                                                                       \
     694             :                                                                                                                                                 \
     695             :         (void) cntxt;                                                                                                           \
     696             :         (void) mb;                                                                                                                      \
     697             :         if ((b1 = BATdescriptor(*bid1)) == NULL) {                                                      \
     698             :                 msg = createException(MAL, "batmtime." MALFUNC,                                       \
     699             :                           SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);                                      \
     700             :                 goto bailout;                                                                                                   \
     701             :         }                                                                                                                                       \
     702             :         b1i = bat_iterator(b1);                                                                                         \
     703             :         if (sid1 && !is_bat_nil(*sid1) && (s1 = BATdescriptor(*sid1)) == NULL) { \
     704             :                 msg = createException(MAL, "batmtime." MALFUNC,                                       \
     705             :                           SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);                                      \
     706             :                 goto bailout;                                                                                                   \
     707             :         }                                                                                                                                       \
     708             :         canditer_init(&ci1, b1, s1);                                                                                \
     709             :         if ((bn = COLnew(ci1.hseq, TYPE_##OUTTYPE, ci1.ncand, TRANSIENT)) == NULL) { \
     710             :                 msg = createException(MAL, "batmtime." MALFUNC,                                       \
     711             :                           SQLSTATE(HY013) MAL_MALLOC_FAIL);                                                     \
     712             :                 goto bailout;                                                                                                   \
     713             :         }                                                                                                                                       \
     714             :         off1 = b1->hseqbase;                                                                                         \
     715             :         INIT_SRC1(1);                                                                                                           \
     716             :         INIT_OUTPUT(n);                                                                                                         \
     717             :         if (ci1.tpe == cand_dense) {                                                                            \
     718             :                 for (BUN i = 0; i < ci1.ncand; i++) {                                                        \
     719             :                         oid p1 = (canditer_next_dense(&ci1) - off1);                                \
     720             :                         FUNC_CALL(FUNC, res, GET_NEXT_SRC1(1, p1), src2, *extra);       \
     721             :                         APPEND_NEXT(MALFUNC);                                                                           \
     722             :                         nils |= is_##OUTTYPE##_nil(res);                                                        \
     723             :                 }                                                                                                                               \
     724             :         } else {                                                                                                                        \
     725             :                 for (BUN i = 0; i < ci1.ncand; i++) {                                                        \
     726             :                         oid p1 = (canditer_next(&ci1) - off1);                                              \
     727             :                         FUNC_CALL(FUNC, res, GET_NEXT_SRC1(1, p1), src2, *extra);       \
     728             :                         APPEND_NEXT(MALFUNC);                                                                           \
     729             :                         nils |= is_##OUTTYPE##_nil(res);                                                        \
     730             :                 }                                                                                                                               \
     731             :         }                                                                                                                                       \
     732             :         BATsetcount(bn, ci1.ncand);                                                                                     \
     733             :         bn->tnonil = !nils;                                                                                                  \
     734             :         bn->tnil = nils;                                                                                                     \
     735             :         bn->tsorted = ci1.ncand < 2;                                                                              \
     736             :         bn->trevsorted = ci1.ncand < 2;                                                                           \
     737             :         bn->tkey = ci1.ncand < 2;                                                                                 \
     738             : bailout:                                                                                                                                \
     739             :         CLEAR_EXTRA_MULTI(res);                                                                                         \
     740             :         if (b1) {                                                                                                                       \
     741             :                 bat_iterator_end(&b1i);                                                                                     \
     742             :                 BBPunfix(b1->batCacheid);                                                                            \
     743             :         }                                                                                                                                       \
     744             :         BBPreclaim(s1);                                                                                                         \
     745             :         if (bn) {                                                                                                                       \
     746             :                 if (msg)                                                                                                                \
     747             :                         BBPreclaim(bn);                                                                                         \
     748             :                 else {                                                                                                                  \
     749             :                         *ret = bn->batCacheid;                                                                               \
     750             :                         BBPkeepref(bn);                                                                                         \
     751             :                 }                                                                                                                               \
     752             :         }                                                                                                                                       \
     753             :         return msg;                                                                                                                     \
     754             : }
     755             : 
     756             : #define func3_noexcept(FUNC, RET, PARAM1, PARAM2, E) RET = FUNC(PARAM1, PARAM2, E)
     757             : #define func3_except(FUNC, RET, PARAM1, PARAM2, E) msg = FUNC(&RET, PARAM1, PARAM2, E); if (msg) break
     758             : 
     759          69 : func2(MTIMEdate_diff, "diff",
     760             :           date, date, lng, date_diff_imp, func2_noexcept,
     761             :           DEC_VAR, DEC_VAR, DEC_VAR_R, DEC_INT,
     762             :           INIT_VARIN, INIT_VARIN, INIT_VAROUT,
     763             :           GET_NEXT_VAR, GET_NEXT_VAR, APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
     764          31 : func2(MTIMEdaytime_diff_msec, "diff",
     765             :           daytime, daytime, lng, daytime_diff, func2_noexcept,
     766             :           DEC_VAR, DEC_VAR, DEC_VAR_R, DEC_INT,
     767             :           INIT_VARIN, INIT_VARIN, INIT_VAROUT,
     768             :           GET_NEXT_VAR, GET_NEXT_VAR, APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
     769          27 : func2(MTIMEdate_sub_msec_interval, "date_sub_msec_interval",
     770             :           date, lng, date, date_sub_msec_interval, func2_except,
     771             :           DEC_VAR_R, DEC_VAR_R, DEC_VAR_R, DEC_INT,
     772             :           INIT_VARIN, INIT_VARIN, INIT_VAROUT,
     773             :           GET_NEXT_VAR, GET_NEXT_VAR, APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
     774        2260 : func2(MTIMEdate_add_msec_interval, "date_add_msec_interval",
     775             :           date, lng, date, date_add_msec_interval, func2_except,
     776             :           DEC_VAR_R, DEC_VAR_R, DEC_VAR_R, DEC_INT,
     777             :           INIT_VARIN, INIT_VARIN, INIT_VAROUT,
     778             :           GET_NEXT_VAR, GET_NEXT_VAR, APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
     779         400 : func2(MTIMEtimestamp_sub_msec_interval, "timestamp_sub_msec_interval",
     780             :           timestamp, lng, timestamp, timestamp_sub_msec_interval, func2_except,
     781             :           DEC_VAR_R, DEC_VAR_R, DEC_VAR_R, DEC_INT,
     782             :           INIT_VARIN, INIT_VARIN, INIT_VAROUT,
     783             :           GET_NEXT_VAR, GET_NEXT_VAR, APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
     784         552 : func2(MTIMEtimestamp_add_msec_interval, "timestamp_add_msec_interval",
     785             :           timestamp, lng, timestamp, timestamp_add_msec_interval, func2_except,
     786             :           DEC_VAR_R, DEC_VAR_R, DEC_VAR_R, DEC_INT,
     787             :           INIT_VARIN, INIT_VARIN, INIT_VAROUT,
     788             :           GET_NEXT_VAR, GET_NEXT_VAR, APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
     789           2 : func2(MTIMEodbc_timestamp_add_msec_interval_time,
     790             :           "odbc_timestamp_add_msec_time", daytime, lng, timestamp,
     791             :           odbc_timestamp_add_msec_interval_time, func2_except, DEC_VAR_R, DEC_VAR_R,
     792             :           DEC_VAR_R, DEC_INT, INIT_VARIN, INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR,
     793             :           GET_NEXT_VAR, APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
     794           0 : func2(MTIMEodbc_timestamp_add_month_interval_time,
     795             :           "odbc_timestamp_add_month_time", daytime, int, timestamp,
     796             :           odbc_timestamp_add_month_interval_time, func2_except, DEC_VAR_R,
     797             :           DEC_VAR_R, DEC_VAR_R, DEC_INT, INIT_VARIN, INIT_VARIN, INIT_VAROUT,
     798             :           GET_NEXT_VAR, GET_NEXT_VAR, APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
     799           2 : func2(MTIMEodbc_timestamp_add_msec_interval_date,
     800             :           "odbc_timestamp_add_msec_date", date, lng, timestamp,
     801             :           odbc_timestamp_add_msec_interval_date, func2_except, DEC_VAR_R, DEC_VAR_R,
     802             :           DEC_VAR_R, DEC_INT, INIT_VARIN, INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR,
     803             :           GET_NEXT_VAR, APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
     804           6 : func2(MTIMEtimestamp_sub_month_interval, "timestamp_sub_month_interval",
     805             :           timestamp, int, timestamp, timestamp_sub_month_interval, func2_except,
     806             :           DEC_VAR_R, DEC_VAR_R, DEC_VAR_R, DEC_INT, INIT_VARIN, INIT_VARIN,
     807             :           INIT_VAROUT, GET_NEXT_VAR, GET_NEXT_VAR, APPEND_VAR, FINISH_INT_SINGLE,
     808             :           CLEAR_NOTHING)
     809           8 : func2(MTIMEtimestamp_add_month_interval, "timestamp_add_month_interval",
     810             :           timestamp, int, timestamp, timestamp_add_month_interval, func2_except,
     811             :           DEC_VAR_R, DEC_VAR_R, DEC_VAR_R, DEC_INT, INIT_VARIN, INIT_VARIN,
     812             :           INIT_VAROUT, GET_NEXT_VAR, GET_NEXT_VAR, APPEND_VAR, FINISH_INT_SINGLE,
     813             :           CLEAR_NOTHING)
     814          30 : func2(MTIMEtime_sub_msec_interval, "time_sub_msec_interval", daytime, lng,
     815             :           daytime, time_sub_msec_interval, func2_noexcept, DEC_VAR_R, DEC_VAR_R,
     816             :           DEC_VAR_R, DEC_INT, INIT_VARIN, INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR,
     817             :           GET_NEXT_VAR, APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
     818          31 : func2(MTIMEtime_add_msec_interval, "time_add_msec_interval", daytime, lng,
     819             :           daytime, time_add_msec_interval, func2_noexcept, DEC_VAR_R, DEC_VAR_R,
     820             :           DEC_VAR_R, DEC_INT, INIT_VARIN, INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR,
     821             :           GET_NEXT_VAR, APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
     822           7 : func2(MTIMEdate_submonths, "date_sub_month_interval", date, int, date, date_submonths,
     823             :           func2_except, DEC_VAR_R, DEC_VAR_R, DEC_VAR_R, DEC_INT, INIT_VARIN,
     824             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR, GET_NEXT_VAR, APPEND_VAR,
     825             :           FINISH_INT_SINGLE, CLEAR_NOTHING)
     826          15 : func2(MTIMEdate_addmonths, "addmonths", date, int, date, date_addmonths,
     827             :           func2_except, DEC_VAR_R, DEC_VAR_R, DEC_VAR_R, DEC_INT, INIT_VARIN,
     828             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR, GET_NEXT_VAR, APPEND_VAR,
     829             :           FINISH_INT_SINGLE, CLEAR_NOTHING)
     830          27 : func1(MTIMEdate_extract_century, "century", date, int, date_century,
     831             :           COPYFLAGS, func1_noexcept, DEC_VAR_R, DEC_VAR_R, INIT_VARIN, INIT_VAROUT,
     832             :           GET_NEXT_VAR)
     833           8 : func1(MTIMEdate_extract_decade, "decade", date, int, date_decade,
     834             :           COPYFLAGS, func1_noexcept, DEC_VAR_R, DEC_VAR_R, INIT_VARIN, INIT_VAROUT,
     835             :           GET_NEXT_VAR)
     836     1507492 : func1(MTIMEdate_extract_year, "year", date, int, date_year, COPYFLAGS,
     837             :           func1_noexcept, DEC_VAR_R, DEC_VAR_R, INIT_VARIN, INIT_VAROUT,
     838             :           GET_NEXT_VAR)
     839          36 : func1(MTIMEdate_extract_quarter, "quarter", date, bte, date_quarter,
     840             :           SETFLAGS, func1_noexcept, DEC_VAR_R, DEC_VAR_R, INIT_VARIN, INIT_VAROUT,
     841             :           GET_NEXT_VAR)
     842     1600207 : func1(MTIMEdate_extract_month, "month", date, bte, date_month, SETFLAGS,
     843             :           func1_noexcept, DEC_VAR_R, DEC_VAR_R, INIT_VARIN, INIT_VAROUT,
     844             :           GET_NEXT_VAR)
     845     1600109 : func1(MTIMEdate_extract_day, "day", date, bte, date_day, SETFLAGS,
     846             :           func1_noexcept, DEC_VAR_R, DEC_VAR_R, INIT_VARIN, INIT_VAROUT,
     847             :           GET_NEXT_VAR)
     848          40 : func1(MTIMEdate_extract_dayofyear, "dayofyear", date, sht, date_dayofyear,
     849             :           SETFLAGS, func1_noexcept, DEC_VAR_R, DEC_VAR_R, INIT_VARIN, INIT_VAROUT,
     850             :           GET_NEXT_VAR)
     851         147 : func1(MTIMEdate_extract_weekofyear, "weekofyear", date, bte,
     852             :           date_weekofyear, SETFLAGS, func1_noexcept, DEC_VAR_R, DEC_VAR_R,
     853             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     854           1 : func1(MTIMEdate_extract_usweekofyear, "usweekofyear", date, bte,
     855             :           date_usweekofyear, SETFLAGS, func1_noexcept, DEC_VAR_R, DEC_VAR_R,
     856             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     857          44 : func1(MTIMEdate_extract_dayofweek, "dayofweek", date, bte, date_dayofweek,
     858             :           SETFLAGS, func1_noexcept, DEC_VAR_R, DEC_VAR_R, INIT_VARIN, INIT_VAROUT,
     859             :           GET_NEXT_VAR)
     860          17 : func1(MTIMEdate_extract_epoch_ms, "epoch_ms", date, lng,
     861             :           date_to_msec_since_epoch, COPYFLAGS, func1_noexcept, DEC_VAR_R, DEC_VAR_R,
     862             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     863     1600049 : func1(MTIMEdaytime_extract_hours, "hours", daytime, bte, daytime_hour,
     864             :           COPYFLAGS, func1_noexcept, DEC_VAR_R, DEC_VAR_R, INIT_VARIN, INIT_VAROUT,
     865             :           GET_NEXT_VAR)
     866     1700051 : func1(MTIMEdaytime_extract_minutes, "minutes", daytime, bte,
     867             :           daytime_min, SETFLAGS, func1_noexcept, DEC_VAR_R, DEC_VAR_R, INIT_VARIN,
     868             :           INIT_VAROUT, GET_NEXT_VAR)
     869     1600045 : func1(MTIMEdaytime_extract_sql_seconds, "sql_seconds", daytime, int,
     870             :           daytime_sec_usec, SETFLAGS, func1_noexcept, DEC_VAR_R, DEC_VAR_R,
     871             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     872           9 : func1(MTIMEdaytime_extract_epoch_ms, "epoch_ms", daytime, lng,
     873             :           daytime_to_msec_since_epoch, COPYFLAGS, func1_noexcept, DEC_VAR_R,
     874             :           DEC_VAR_R, INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     875         145 : func2(MTIMEtimestamp_diff_msec, "diff", timestamp, timestamp, lng, TSDIFF,
     876             :           func2_noexcept, DEC_VAR, DEC_VAR, DEC_VAR_R, DEC_INT, INIT_VARIN,
     877             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR, GET_NEXT_VAR, APPEND_VAR,
     878             :           FINISH_INT_SINGLE, CLEAR_NOTHING)
     879          19 : func1(MTIMEtimestamp_century, "century", timestamp, int,
     880             :           timestamp_century, COPYFLAGS, func1_noexcept, DEC_VAR_R, DEC_VAR_R,
     881             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     882           0 : func1(MTIMEtimestamp_decade, "decade", timestamp, int,
     883             :           timestamp_decade, COPYFLAGS, func1_noexcept, DEC_VAR_R, DEC_VAR_R,
     884             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     885     1700080 : func1(MTIMEtimestamp_year, "year", timestamp, int, timestamp_year,
     886             :           COPYFLAGS, func1_noexcept, DEC_VAR_R, DEC_VAR_R, INIT_VARIN, INIT_VAROUT,
     887             :           GET_NEXT_VAR)
     888          40 : func1(MTIMEtimestamp_quarter, "quarter", timestamp, bte,
     889             :           timestamp_quarter, SETFLAGS, func1_noexcept, DEC_VAR_R, DEC_VAR_R,
     890             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     891     1400393 : func1(MTIMEtimestamp_month, "month", timestamp, bte, timestamp_month,
     892             :           SETFLAGS, func1_noexcept, DEC_VAR_R, DEC_VAR_R, INIT_VARIN, INIT_VAROUT,
     893             :           GET_NEXT_VAR)
     894     1700058 : func1(MTIMEtimestamp_day, "day", timestamp, bte, timestamp_day,
     895             :           SETFLAGS, func1_noexcept, DEC_VAR_R, DEC_VAR_R, INIT_VARIN, INIT_VAROUT,
     896             :           GET_NEXT_VAR)
     897     1700128 : func1(MTIMEtimestamp_hours, "hours", timestamp, bte, timestamp_hours,
     898             :           SETFLAGS, func1_noexcept, DEC_VAR_R, DEC_VAR_R, INIT_VARIN, INIT_VAROUT,
     899             :           GET_NEXT_VAR)
     900     1500128 : func1(MTIMEtimestamp_minutes, "minutes", timestamp, bte,
     901             :           timestamp_minutes, SETFLAGS, func1_noexcept, DEC_VAR_R, DEC_VAR_R,
     902             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     903     1700145 : func1(MTIMEtimestamp_sql_seconds, "sql_seconds", timestamp, int,
     904             :           timestamp_extract_usecond, SETFLAGS, func1_noexcept, DEC_VAR_R, DEC_VAR_R,
     905             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     906          19 : func1(MTIMEtimestamp_extract_epoch_ms, "epoch_ms", timestamp, lng,
     907             :           timestamp_to_msec_since_epoch, COPYFLAGS, func1_noexcept, DEC_VAR_R,
     908             :           DEC_VAR_R, INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     909           1 : func1(MTIMEsql_year, "year", int, int, sql_year, COPYFLAGS, func1_noexcept,
     910             :           DEC_VAR_R, DEC_VAR_R, INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     911           0 : func1(MTIMEsql_month, "month", int, int, sql_month, SETFLAGS,
     912             :           func1_noexcept, DEC_VAR_R, DEC_VAR_R, INIT_VARIN, INIT_VAROUT,
     913             :           GET_NEXT_VAR)
     914           3 : func1(MTIMEsql_day, "day", lng, lng, sql_day, COPYFLAGS, func1_noexcept,
     915             :           DEC_VAR_R, DEC_VAR_R, INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     916           2 : func1(MTIMEsql_hours, "hours", lng, int, sql_hours, SETFLAGS,
     917             :           func1_noexcept, DEC_VAR_R, DEC_VAR_R, INIT_VARIN, INIT_VAROUT,
     918             :           GET_NEXT_VAR)
     919           5 : func1(MTIMEsql_minutes, "minutes", lng, int, sql_minutes, SETFLAGS,
     920             :           func1_noexcept, DEC_VAR_R, DEC_VAR_R, INIT_VARIN, INIT_VAROUT,
     921             :           GET_NEXT_VAR)
     922           3 : func1(MTIMEsql_seconds, "seconds", lng, int, sql_seconds, SETFLAGS,
     923             :           func1_noexcept, DEC_VAR_R, DEC_VAR_R, INIT_VARIN, INIT_VAROUT,
     924             :           GET_NEXT_VAR)
     925           2 : func1(MTIMEmsec_extract_epoch_ms, "epoch_ms", lng, lng, msec_since_epoch,
     926             :           COPYFLAGS, func1_noexcept, DEC_VAR_R, DEC_VAR_R, INIT_VARIN, INIT_VAROUT,
     927             :           GET_NEXT_VAR)
     928             : static inline str
     929          20 : date_fromstr_func(date *ret, str s)
     930             : {
     931          20 :         if (date_fromstr(s, &(size_t) { sizeof(date) }, &ret, false) < 0) {
     932          10 :                 if (strNil(s))
     933          10 :                         throw(MAL, "mtime.date_fromstr",
     934             :                                   SQLSTATE(42000) "Conversion of NULL string to date failed");
     935          10 :                 throw(MAL, "mtime.date_fromstr",
     936             :                           SQLSTATE(22007) "Conversion of string '%s' to date failed", s);
     937             :         }
     938          10 :         return MAL_SUCCEED;
     939             : }
     940             : 
     941          22 : func1(MTIMEdate_fromstr, "date", str, date,
     942             :           date_fromstr_func, SETFLAGS, func1_except,
     943             :           DEC_ITER, DEC_VAR_R, INIT_ITERIN, INIT_VAROUT, GET_NEXT_ITER)
     944             : #define date_date(m) m
     945          86 : func1(MTIMEdate_date, "date", date, date,
     946             :           date_date, COPYFLAGS, func1_noexcept,
     947             :           DEC_VAR_R, DEC_VAR_R, INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     948         188 : func1(MTIMEtimestamp_extract_date, "date", timestamp, date,
     949             :           timestamp_date, COPYFLAGS, func1_noexcept,
     950             :           DEC_VAR_R, DEC_VAR_R, INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     951             : 
     952             : static inline date
     953          69 : timestamp_tz_date(timestamp ts, lng tz_msec)
     954             : {
     955          69 :         ts = timestamp_add_usec(ts, tz_msec * LL_CONSTANT(1000));
     956          69 :         return timestamp_date(ts);
     957             : }
     958             : 
     959          79 : func2(MTIMEtimestamp_tz_extract_date, "date",
     960             :           timestamp, lng, date, timestamp_tz_date, func2_noexcept,
     961             :           DEC_VAR, DEC_VAR, DEC_VAR_R, DEC_INT,
     962             :           INIT_VARIN, INIT_VARIN, INIT_VAROUT,
     963             :           GET_NEXT_VAR, GET_NEXT_VAR, APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
     964             : 
     965             : static inline str
     966           0 : timestamp_fromstr_func(timestamp *ret, str s)
     967             : {
     968           0 :         if (timestamp_fromstr(s, &(size_t) { sizeof(timestamp) }, &ret, false) < 0)
     969           0 :                 throw(MAL, "mtime.timestamp_fromstr", GDK_EXCEPTION);
     970           0 :         return MAL_SUCCEED;
     971             : }
     972             : 
     973           0 : func1(MTIMEtimestamp_fromstr, "timestamp", str, timestamp,
     974             :           timestamp_fromstr_func, SETFLAGS, func1_except,
     975             :           DEC_ITER, DEC_VAR_R, INIT_ITERIN, INIT_VAROUT, GET_NEXT_ITER)
     976             : #define timestamp_timestamp(m) m
     977           0 : func1(MTIMEtimestamp_timestamp, "timestamp", timestamp, timestamp,
     978             :           timestamp_timestamp, COPYFLAGS, func1_noexcept,
     979             :           DEC_VAR_R, DEC_VAR_R, INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     980             : #define mkts(dt)        timestamp_create(dt, daytime_create(0, 0, 0, 0))
     981           0 : func1(MTIMEtimestamp_fromdate, "timestamp", date, timestamp,
     982             :           mkts, COPYFLAGS, func1_noexcept,
     983             :           DEC_VAR_R, DEC_VAR_R, INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     984             : #define seconds_since_epoch(t) is_timestamp_nil(t) ? int_nil : (int) (timestamp_diff(t, unixepoch) / 1000000);
     985         159 : func1(MTIMEseconds_since_epoch, "epoch", timestamp, int,
     986             :           seconds_since_epoch, COPYFLAGS, func1_noexcept,
     987             :           DEC_VAR_R, DEC_VAR_R, INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
     988             : #define mktsfromsec(sec)        (is_int_nil(sec) ?                                                      \
     989             :                                                          timestamp_nil :                                                        \
     990             :                                                          timestamp_add_usec(unixepoch,                          \
     991             :                                                                                                 (sec) * LL_CONSTANT(1000000)))
     992             : #define mktsfrommsec(msec)      (is_lng_nil(msec) ?                                                     \
     993             :                                                          timestamp_nil :                                                        \
     994             :                                                          timestamp_add_usec(unixepoch,                          \
     995             :                                                                                                 (msec) * LL_CONSTANT(1000)))
     996             : /* TODO later I have to remove this call */
     997           6 : func1(MTIMEtimestamp_fromsecond_epoch, "epoch", int,
     998             :           timestamp, mktsfromsec, COPYFLAGS, func1_noexcept, DEC_VAR_R, DEC_VAR_R,
     999             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
    1000           0 : func1(MTIMEtimestamp_fromsecond, "timestamp", int, timestamp,
    1001             :           mktsfromsec, COPYFLAGS, func1_noexcept, DEC_VAR_R, DEC_VAR_R, INIT_VARIN,
    1002             :           INIT_VAROUT, GET_NEXT_VAR)
    1003             : /* TODO later I have to remove this call */
    1004           2 : func1(MTIMEtimestamp_frommsec_epoch, "epoch", lng, timestamp,
    1005             :           mktsfrommsec, COPYFLAGS, func1_noexcept,
    1006             :           DEC_VAR_R, DEC_VAR_R, INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
    1007           0 : func1(MTIMEtimestamp_frommsec, "timestamp", lng, timestamp,
    1008             :           mktsfrommsec, COPYFLAGS, func1_noexcept,
    1009             :           DEC_VAR_R, DEC_VAR_R, INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
    1010             : static inline str
    1011           3 : daytime_fromstr_func(daytime *ret, str s)
    1012             : {
    1013           3 :         if (daytime_fromstr(s, &(size_t) { sizeof(daytime) }, &ret, false) < 0)
    1014           0 :                 throw(MAL, "mtime.daytime_fromstr", GDK_EXCEPTION);
    1015           3 :         return MAL_SUCCEED;
    1016             : }
    1017             : 
    1018           3 : func1(MTIMEdaytime_fromstr, "daytime", str, daytime,
    1019             :           daytime_fromstr_func, SETFLAGS, func1_except,
    1020             :           DEC_ITER, DEC_VAR_R, INIT_ITERIN, INIT_VAROUT, GET_NEXT_ITER)
    1021             : #define daytime_daytime(m) m
    1022           0 : func1(MTIMEdaytime_daytime, "daytime", daytime, daytime,
    1023             :           daytime_daytime, COPYFLAGS, func1_noexcept,
    1024             :           DEC_VAR_R, DEC_VAR_R, INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
    1025             : static inline str
    1026           0 : daytime_fromseconds(daytime *ret, lng secs)
    1027             : {
    1028           0 :         if (is_lng_nil(secs))
    1029           0 :                 *ret = daytime_nil;
    1030           0 :         else if (secs < 0 || secs >= 24 * 60 * 60)
    1031           0 :                 throw(MAL, "mtime.daytime_fromseconds",
    1032             :                           SQLSTATE(42000) ILLEGAL_ARGUMENT);
    1033             :         else
    1034           0 :                 *ret = (daytime) (secs * 1000000);
    1035             :         return MAL_SUCCEED;
    1036             : }
    1037             : 
    1038           0 : func1(MTIMEdaytime_fromseconds, "daytime", lng, daytime,
    1039             :           daytime_fromseconds, COPYFLAGS, func1_except,
    1040             :           DEC_VAR_R, DEC_VAR_R, INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
    1041           0 : func1(MTIMEtimestamp_extract_daytime, "daytime", timestamp,
    1042             :           daytime, timestamp_daytime, SETFLAGS, func1_noexcept, DEC_VAR_R,
    1043             :           DEC_VAR_R, INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR)
    1044             : /* return current system time zone offset in seconds East of Greenwich */
    1045             : static int
    1046           2 : local_timezone(int *isdstp)
    1047             : {
    1048           2 :         int tzone = 0;
    1049           2 :         int isdst = -1;
    1050             : 
    1051             : #if defined(_MSC_VER)
    1052             :         DYNAMIC_TIME_ZONE_INFORMATION tzinf;
    1053             : 
    1054             :         /* documentation says: UTC = localtime + Bias (in minutes),
    1055             :          * but experimentation during DST period says, UTC = localtime
    1056             :          * + Bias + DaylightBias, and presumably during non DST
    1057             :          * period, UTC = localtime + Bias */
    1058             :         switch (GetDynamicTimeZoneInformation(&tzinf)) {
    1059             :         case TIME_ZONE_ID_STANDARD:     /* using standard time */
    1060             :         case TIME_ZONE_ID_UNKNOWN:      /* no daylight saving time in this zone */
    1061             :                 isdst = 0;
    1062             :                 tzone = -(int) tzinf.Bias * 60;
    1063             :                 break;
    1064             :         case TIME_ZONE_ID_DAYLIGHT:     /* using daylight saving time */
    1065             :                 isdst = 1;
    1066             :                 tzone = -(int) (tzinf.Bias + tzinf.DaylightBias) * 60;
    1067             :                 break;
    1068             :         default:                                        /* aka TIME_ZONE_ID_INVALID */
    1069             :                 /* call failed, we don't know the time zone */
    1070             :                 tzone = 0;
    1071             :                 break;
    1072             :         }
    1073             : #elif defined(HAVE_TM_GMTOFF)
    1074           2 :         time_t t;
    1075           2 :         struct tm tm = (struct tm) { 0 };
    1076             : 
    1077           2 :         if ((t = time(NULL)) != (time_t) - 1 && localtime_r(&t, &tm)) {
    1078           2 :                 tzone = (int) tm.tm_gmtoff;
    1079           2 :                 isdst = tm.tm_isdst;
    1080             :         }
    1081             : #else
    1082             :         time_t t;
    1083             :         struct tm tm = (struct tm) { 0 };
    1084             : 
    1085             :         if ((t = time(NULL)) != (time_t) - 1 && gmtime_r(&t, &tm)) {
    1086             :                 timestamp lt, gt;
    1087             :                 gt = timestamp_create(date_create(tm.tm_year + 1900,
    1088             :                                                                                   tm.tm_mon + 1,
    1089             :                                                                                   tm.tm_mday),
    1090             :                                                           daytime_create(tm.tm_hour,
    1091             :                                                                                          tm.tm_min,
    1092             :                                                                                          tm.tm_sec == 60 ? 59 : tm.tm_sec,
    1093             :                                                                                          0));
    1094             :                 if (localtime_r(&t, &tm)) {
    1095             :                         isdst = tm.tm_isdst;
    1096             :                         lt = timestamp_create(date_create(tm.tm_year + 1900,
    1097             :                                                                                           tm.tm_mon + 1,
    1098             :                                                                                           tm.tm_mday),
    1099             :                                                                   daytime_create(tm.tm_hour,
    1100             :                                                                                                  tm.tm_min,
    1101             :                                                                                                  tm.tm_sec == 60 ? 59 : tm.tm_sec, 0));
    1102             :                         tzone = (int) (timestamp_diff(lt, gt) / 1000000);
    1103             :                 }
    1104             :         }
    1105             : #endif
    1106           2 :         if (isdstp)
    1107           2 :                 *isdstp = isdst;
    1108           2 :         return tzone;
    1109             : }
    1110             : 
    1111             : static str
    1112           0 : MTIMElocal_timezone_msec(lng *ret)
    1113             : {
    1114           0 :         int tzone = local_timezone(NULL);
    1115           0 :         *ret = (lng) tzone *1000;
    1116           0 :         return MAL_SUCCEED;
    1117             : }
    1118             : 
    1119             : static str
    1120          47 : timestamp_to_str_withtz(str *buf, const timestamp *d, str *format, const char *type,
    1121             :                                  const char *malfunc, long gmtoff)
    1122             : {
    1123          47 :         date dt;
    1124          47 :         daytime t;
    1125          47 :         struct tm tm;
    1126             : 
    1127          47 :         if (is_timestamp_nil(*d) || strNil(*format)) {
    1128           4 :                 strcpy(*buf, str_nil);
    1129           4 :                 return MAL_SUCCEED;
    1130             :         }
    1131          43 :         dt = timestamp_date(*d);
    1132          43 :         t = timestamp_daytime(*d);
    1133          43 :         tm = (struct tm) {
    1134          43 :                 .tm_year = date_year(dt) - 1900,
    1135          43 :                 .tm_mon = date_month(dt) - 1,
    1136          43 :                 .tm_mday = date_day(dt),
    1137          43 :                 .tm_wday = date_dayofweek(dt) % 7,
    1138          43 :                 .tm_yday = date_dayofyear(dt) - 1,
    1139          43 :                 .tm_hour = daytime_hour(t),
    1140          43 :                 .tm_min = daytime_min(t),
    1141          43 :                 .tm_sec = daytime_sec(t),
    1142             : #if defined(HAVE_TM_GMTOFF)
    1143             :                 .tm_gmtoff = gmtoff,
    1144             : #endif
    1145             :         };
    1146          43 :         if (strftime(*buf, MTIME_STR_BUFFER_LENGTH, *format, &tm) == 0)
    1147           0 :                 throw(MAL, malfunc, "cannot convert %s", type);
    1148             :         return MAL_SUCCEED;
    1149             : }
    1150             : 
    1151             : static str
    1152          41 : timestamp_to_str(str *buf, const timestamp *d, str *format, const char *type,
    1153             :                                  const char *malfunc)
    1154             : {
    1155          41 :         return timestamp_to_str_withtz( buf, d, format, type, malfunc, 0);
    1156             : }
    1157             : 
    1158             : static str
    1159           6 : timestamptz_to_str(str *buf, const timestamp *d, str *format, const char *type,
    1160             :                                  const char *malfunc, long gmtoff)
    1161             : {
    1162           6 :         timestamp t = *d;
    1163           6 :         t = timestamp_add_usec(t, gmtoff * LL_CONSTANT(1000000));
    1164           6 :         return timestamp_to_str_withtz( buf, &t, format, type, malfunc, gmtoff);
    1165             : }
    1166             : 
    1167             : 
    1168             : static str
    1169         203 : str_to_timestamp(timestamp *ret, str *s, str *format, const long gmtoff, const char *type,
    1170             :                                  const char *malfunc)
    1171             : {
    1172         203 :         struct tm tm = (struct tm) { 0 };
    1173             : 
    1174         406 :         if (strNil(*s) || strNil(*format)) {
    1175           0 :                 *ret = timestamp_nil;
    1176           0 :                 return MAL_SUCCEED;
    1177             :         }
    1178         203 :         tm.tm_sec = tm.tm_min = tm.tm_hour = 0;
    1179         203 :         tm.tm_isdst = -1;
    1180         203 :         tm.tm_mday = 1;
    1181         203 :         if (strptime(*s, *format, &tm) == NULL)
    1182           0 :                 throw(MAL, malfunc,
    1183             :                           "format '%s', doesn't match %s '%s'", *format, type, *s);
    1184         406 :         *ret = timestamp_create(date_create(tm.tm_year + 1900,
    1185         203 :                                                                                 tm.tm_mon + 1,
    1186             :                                                                                 tm.tm_mday),
    1187             :                                                         daytime_create(tm.tm_hour,
    1188             :                                                                                    tm.tm_min,
    1189         203 :                                                                                    tm.tm_sec == 60 ? 59 : tm.tm_sec,
    1190             :                                                                                    0));
    1191             :         /* if strptime filled in DST information (tm_isdst >= 0), then the
    1192             :          * time is in system local time and we convert to GMT by
    1193             :          * subtracting the time zone offset, else we don't touch the time
    1194             :          * returned because it is assumed to already be in GMT */
    1195         203 :         if (tm.tm_isdst >= 0) {
    1196           2 :                 int isdst = 0;
    1197           2 :                 int tz = local_timezone(&isdst);
    1198             :                 /* if strptime's information doesn't square with our own
    1199             :                  * information about having or not having DST, we compensate
    1200             :                  * an hour */
    1201           2 :                 if (tm.tm_isdst > 0 && isdst == 0) {
    1202           0 :                         tz += 3600;
    1203           2 :                 } else if (tm.tm_isdst == 0 && isdst > 0) {
    1204           2 :                         tz -= 3600;
    1205             :                 }
    1206             : 
    1207           2 :                 *ret = timestamp_add_usec(*ret, -tz * LL_CONSTANT(1000000));
    1208             :         } else {
    1209         201 :                 *ret = timestamp_add_usec(*ret, -gmtoff * LL_CONSTANT(1000000));
    1210             :         }
    1211         203 :         if (is_timestamp_nil(*ret))
    1212           0 :                 throw(MAL, malfunc, "bad %s '%s'", type, *s);
    1213             :         return MAL_SUCCEED;
    1214             : }
    1215             : 
    1216             : static inline str
    1217         194 : str_to_date(date *ret, str s, str format, lng tz_msec)
    1218             : {
    1219         194 :         str msg = MAL_SUCCEED;
    1220         194 :         timestamp ts;
    1221         194 :         (void)tz_msec;
    1222         194 :         if ((msg = str_to_timestamp(&ts, &s, &format, /*tz_msec/1000*/0, "date",
    1223             :                                                                 "mtime.str_to_date")) != MAL_SUCCEED)
    1224             :                 return msg;
    1225         194 :         *ret = timestamp_date(ts);
    1226         194 :         return MAL_SUCCEED;
    1227             : }
    1228             : 
    1229         195 : func3(MTIMEstr_to_date, "str_to_date",
    1230             :           str, str, date, str_to_date, func3_except,
    1231             :           DEC_ITER, DEC_ITER, DEC_VAR_R, DEC_INT,
    1232             :           INIT_ITERIN, INIT_ITERIN, INIT_VAROUT,
    1233             :           GET_NEXT_ITER, GET_NEXT_ITER,
    1234             :           APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
    1235             : 
    1236             : static inline str
    1237           2 : str_to_time(daytime *ret, str s, str format, lng tz_msec)
    1238             : {
    1239           2 :         str msg = MAL_SUCCEED;
    1240           2 :         timestamp ts;
    1241           2 :         if ((msg = str_to_timestamp(&ts, &s, &format, (long)(tz_msec/1000), "time",
    1242             :                                                                 "mtime.str_to_time")) != MAL_SUCCEED)
    1243             :                 return msg;
    1244           2 :         *ret = timestamp_daytime(ts);
    1245           2 :         return MAL_SUCCEED;
    1246             : }
    1247             : 
    1248           2 : func3(MTIMEstr_to_time, "str_to_time",
    1249             :           str, str, daytime, str_to_time, func3_except,
    1250             :           DEC_ITER, DEC_ITER, DEC_VAR_R, DEC_INT,
    1251             :           INIT_ITERIN, INIT_ITERIN, INIT_VAROUT,
    1252             :           GET_NEXT_ITER, GET_NEXT_ITER,
    1253             :           APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
    1254             : 
    1255             : static inline str
    1256           7 : str_to_timestamp_func(timestamp *ret, str s, str format, lng tz_msec)
    1257             : {
    1258           7 :         return str_to_timestamp(ret, &s, &format, (long)(tz_msec/1000), "timestamp",
    1259             :                                                         "mtime.str_to_timestamp");
    1260             : }
    1261             : 
    1262           7 : func3(MTIMEstr_to_timestamp, "str_to_timestamp",
    1263             :           str, str, timestamp, str_to_timestamp_func, func3_except,
    1264             :           DEC_ITER, DEC_ITER, DEC_VAR_R, DEC_INT,
    1265             :           INIT_ITERIN, INIT_ITERIN, INIT_VAROUT,
    1266             :           GET_NEXT_ITER, GET_NEXT_ITER,
    1267             :           APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
    1268             : 
    1269             : static inline str
    1270          32 : date_to_str(str *ret, date d, str format)
    1271             : {
    1272          32 :         timestamp ts = timestamp_create(d, timestamp_daytime(timestamp_current()));
    1273          32 :         return timestamp_to_str(ret, &ts, &format, "date", "mtime.date_to_str");
    1274             : }
    1275             : 
    1276          42 : func2(MTIMEdate_to_str, "date_to_str",
    1277             :           date, str, str, date_to_str, func2_except,
    1278             :           DEC_VAR, DEC_ITER, DEC_NOTHING, DEC_BUFFER,
    1279             :           INIT_VARIN, INIT_ITERIN, INIT_NOTHING,
    1280             :           GET_NEXT_VAR, GET_NEXT_ITER,
    1281             :           APPEND_STR, FINISH_BUFFER_SINGLE, FINISH_BUFFER_MULTI)
    1282             : 
    1283             : static inline str
    1284           0 : time_to_str(str *ret, daytime d, str format)
    1285             : {
    1286           0 :         timestamp ts = timestamp_create(timestamp_date(timestamp_current()), d);
    1287           0 :         return timestamp_to_str(ret, &ts, &format, "time", "mtime.time_to_str");
    1288             : }
    1289             : 
    1290           0 : func2(MTIMEtime_to_str, "time_to_str",
    1291             :           daytime, str, str, time_to_str, func2_except,
    1292             :           DEC_VAR, DEC_ITER, DEC_NOTHING, DEC_BUFFER,
    1293             :           INIT_VARIN, INIT_ITERIN, INIT_NOTHING,
    1294             :           GET_NEXT_VAR, GET_NEXT_ITER,
    1295             :           APPEND_STR, FINISH_BUFFER_SINGLE, FINISH_BUFFER_MULTI)
    1296             : 
    1297             : static inline str
    1298           1 : timetz_to_str(str *ret, daytime d, str format, lng tz_msec)
    1299             : {
    1300           1 :         timestamp ts = timestamp_create(timestamp_date(timestamp_current()), d);
    1301           1 :         return timestamptz_to_str(ret, &ts, &format, "time", "mtime.timetz_to_str", (long)(tz_msec/1000));
    1302             : }
    1303           1 : func3(MTIMEtimetz_to_str, "timetz_to_str",
    1304             :           daytime, str, str, timetz_to_str, func3_except,
    1305             :           DEC_VAR, DEC_ITER, DEC_NOTHING, DEC_BUFFER,
    1306             :           INIT_VARIN, INIT_ITERIN, INIT_NOTHING,
    1307             :           GET_NEXT_VAR, GET_NEXT_ITER,
    1308             :           APPEND_STR, FINISH_BUFFER_SINGLE, FINISH_BUFFER_MULTI)
    1309             : 
    1310             : static inline str
    1311           9 : timestamp_to_str_func(str *ret, timestamp d, str format)
    1312             : {
    1313          18 :         return timestamp_to_str(ret, &d, &format, "timestamp", "mtime.timestamp_to_str");
    1314             : }
    1315             : 
    1316          15 : func2(MTIMEtimestamp_to_str, "timestamp_to_str",
    1317             :           timestamp, str, str, timestamp_to_str_func, func2_except,
    1318             :           DEC_VAR, DEC_ITER, DEC_NOTHING, DEC_BUFFER,
    1319             :           INIT_VARIN, INIT_ITERIN, INIT_NOTHING,
    1320             :           GET_NEXT_VAR, GET_NEXT_ITER,
    1321             :           APPEND_STR, FINISH_BUFFER_SINGLE, FINISH_BUFFER_MULTI)
    1322             : 
    1323             : static inline str
    1324           5 : timestamptz_to_str_func(str *ret, timestamp d, str format, lng tz_msec)
    1325             : {
    1326           5 :         return timestamptz_to_str(ret, &d, &format, "timestamp", "mtime.timestamptz_to_str", (long)(tz_msec/1000));
    1327             : }
    1328             : 
    1329           7 : func3(MTIMEtimestamptz_to_str, "timestamptz_to_str",
    1330             :           timestamp, str, str, timestamptz_to_str_func, func3_except,
    1331             :           DEC_VAR, DEC_ITER, DEC_NOTHING, DEC_BUFFER,
    1332             :           INIT_VARIN, INIT_ITERIN, INIT_NOTHING,
    1333             :           GET_NEXT_VAR, GET_NEXT_ITER,
    1334             :           APPEND_STR, FINISH_BUFFER_SINGLE, FINISH_BUFFER_MULTI)
    1335             : 
    1336             : static inline lng
    1337           5 : timestampdiff_sec(timestamp t1, timestamp t2)
    1338             : {
    1339           5 :         return TSDIFF(t1, t2) / 1000;
    1340             : }
    1341             : 
    1342             : static inline lng
    1343           1 : timestampdiff_sec_date_timestamp(date d, timestamp ts)
    1344             : {
    1345           1 :         return timestampdiff_sec(timestamp_fromdate(d), ts);
    1346             : }
    1347             : 
    1348             : static inline lng
    1349           1 : timestampdiff_sec_timestamp_date(timestamp ts, date d)
    1350             : {
    1351           1 :         return timestampdiff_sec(ts, timestamp_fromdate(d));
    1352             : }
    1353             : 
    1354             : static inline lng
    1355           4 : timestampdiff_min(timestamp t1, timestamp t2)
    1356             : {
    1357           4 :         return TSDIFF(t1, t2) / 1000 / 60;
    1358             : }
    1359             : 
    1360             : static inline lng
    1361           1 : timestampdiff_min_date_timestamp(date d, timestamp ts)
    1362             : {
    1363           1 :         return timestampdiff_min(timestamp_fromdate(d), ts);
    1364             : }
    1365             : 
    1366             : static inline lng
    1367           1 : timestampdiff_min_timestamp_date(timestamp ts, date d)
    1368             : {
    1369           1 :         return timestampdiff_min(ts, timestamp_fromdate(d));
    1370             : }
    1371             : 
    1372             : static inline lng
    1373           4 : timestampdiff_hour(timestamp t1, timestamp t2)
    1374             : {
    1375           4 :         return TSDIFF(t1, t2) / 1000 / 60 / 60;
    1376             : }
    1377             : 
    1378             : static inline lng
    1379           1 : timestampdiff_hour_date_timestamp(date d, timestamp ts)
    1380             : {
    1381           1 :         return timestampdiff_hour(timestamp_fromdate(d), ts);
    1382             : }
    1383             : 
    1384             : static inline lng
    1385           1 : timestampdiff_hour_timestamp_date(timestamp ts, date d)
    1386             : {
    1387           1 :         return timestampdiff_hour(ts, timestamp_fromdate(d));
    1388             : }
    1389             : 
    1390             : static inline int
    1391           4 : timestampdiff_day(timestamp t1, timestamp t2)
    1392             : {
    1393           4 :         return date_diff(timestamp_date(t1), timestamp_date(t2));
    1394             : }
    1395             : 
    1396             : static inline int
    1397           1 : timestampdiff_day_time_timestamp(daytime t, timestamp ts)
    1398             : {
    1399           1 :         date today = timestamp_date(timestamp_current());
    1400           1 :         return timestampdiff_day(timestamp_create(today, t), ts);
    1401             : }
    1402             : 
    1403             : static inline int
    1404           1 : timestampdiff_day_timestamp_time(timestamp ts, daytime t)
    1405             : {
    1406           1 :         date today = timestamp_date(timestamp_current());
    1407           1 :         return timestampdiff_day(ts, timestamp_create(today, t));
    1408             : }
    1409             : 
    1410             : static inline int
    1411           4 : timestampdiff_week(timestamp t1, timestamp t2)
    1412             : {
    1413           4 :         return date_diff(timestamp_date(t1), timestamp_date(t2)) / 7;
    1414             : }
    1415             : 
    1416             : static inline int
    1417           0 : timestampdiff_week_time_timestamp(daytime t, timestamp ts)
    1418             : {
    1419           0 :         date today = timestamp_date(timestamp_current());
    1420           0 :         return timestampdiff_week(timestamp_create(today, t), ts);
    1421             : }
    1422             : 
    1423             : static inline int
    1424           2 : timestampdiff_week_timestamp_time(timestamp ts, daytime t)
    1425             : {
    1426           2 :         date today = timestamp_date(timestamp_current());
    1427           2 :         return timestampdiff_week(ts, timestamp_create(today, t));
    1428             : }
    1429             : 
    1430             : static inline int
    1431           5 : timestampdiff_month(timestamp t1, timestamp t2)
    1432             : {
    1433           5 :         date d1 = timestamp_date(t1);
    1434           5 :         date d2 = timestamp_date(t2);
    1435           5 :         return ((date_year(d1) - date_year(d2)) * 12) + (date_month(d1) -
    1436           5 :                                                                                                          date_month(d2));
    1437             : }
    1438             : 
    1439             : static inline int
    1440           1 : timestampdiff_month_time_timestamp(daytime t, timestamp ts)
    1441             : {
    1442           1 :         date today = timestamp_date(timestamp_current());
    1443           1 :         return timestampdiff_month(timestamp_create(today, t), ts);
    1444             : }
    1445             : 
    1446             : static inline int
    1447           1 : timestampdiff_month_timestamp_time(timestamp ts, daytime t)
    1448             : {
    1449           1 :         date today = timestamp_date(timestamp_current());
    1450           1 :         return timestampdiff_month(ts, timestamp_create(today, t));
    1451             : }
    1452             : 
    1453             : static inline int
    1454           5 : timestampdiff_quarter(timestamp t1, timestamp t2)
    1455             : {
    1456           5 :         date d1 = timestamp_date(t1);
    1457           5 :         date d2 = timestamp_date(t2);
    1458           5 :         return ((date_year(d1) - date_year(d2)) * 4) + (date_quarter(d1) -
    1459           5 :                                                                                                         date_quarter(d2));
    1460             : }
    1461             : 
    1462             : static inline int
    1463           1 : timestampdiff_quarter_time_timestamp(daytime t, timestamp ts)
    1464             : {
    1465           1 :         date today = timestamp_date(timestamp_current());
    1466           1 :         return timestampdiff_quarter(timestamp_create(today, t), ts);
    1467             : }
    1468             : 
    1469             : static inline int
    1470           1 : timestampdiff_quarter_timestamp_time(timestamp ts, daytime t)
    1471             : {
    1472           1 :         date today = timestamp_date(timestamp_current());
    1473           1 :         return timestampdiff_quarter(ts, timestamp_create(today, t));
    1474             : }
    1475             : 
    1476             : static inline int
    1477           4 : timestampdiff_year(timestamp t1, timestamp t2)
    1478             : {
    1479           4 :         date d1 = timestamp_date(t1);
    1480           4 :         date d2 = timestamp_date(t2);
    1481           4 :         return date_year(d1) - date_year(d2);
    1482             : }
    1483             : 
    1484             : static inline int
    1485           1 : timestampdiff_year_time_timestamp(daytime t, timestamp ts)
    1486             : {
    1487           1 :         date today = timestamp_date(timestamp_current());
    1488           1 :         return timestampdiff_year(timestamp_create(today, t), ts);
    1489             : }
    1490             : 
    1491             : static inline int
    1492           1 : timestampdiff_year_timestamp_time(timestamp ts, daytime t)
    1493             : {
    1494           1 :         date today = timestamp_date(timestamp_current());
    1495           1 :         return timestampdiff_year(ts, timestamp_create(today, t));
    1496             : }
    1497             : 
    1498             : // odbc timestampdiff variants
    1499           3 : func2(MTIMEtimestampdiff_sec, "timestampdiff_sec",
    1500             :           timestamp, timestamp, lng, timestampdiff_sec, func2_noexcept,
    1501             :           DEC_VAR, DEC_VAR, DEC_VAR_R, DEC_INT,
    1502             :           INIT_VARIN, INIT_VARIN, INIT_VAROUT,
    1503             :           GET_NEXT_VAR, GET_NEXT_VAR, APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
    1504           1 : func2(MTIMEtimestampdiff_sec_d_ts, "timestampdiff_sec",
    1505             :           date, timestamp, lng, timestampdiff_sec_date_timestamp, func2_noexcept,
    1506             :           DEC_VAR, DEC_VAR, DEC_VAR_R, DEC_INT,
    1507             :           INIT_VARIN, INIT_VARIN, INIT_VAROUT,
    1508             :           GET_NEXT_VAR, GET_NEXT_VAR, APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
    1509           1 : func2(MTIMEtimestampdiff_sec_ts_d, "timestampdiff_sec",
    1510             :           timestamp, date, lng, timestampdiff_sec_timestamp_date, func2_noexcept,
    1511             :           DEC_VAR, DEC_VAR, DEC_VAR_R, DEC_INT,
    1512             :           INIT_VARIN, INIT_VARIN, INIT_VAROUT,
    1513             :           GET_NEXT_VAR, GET_NEXT_VAR, APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
    1514           2 : func2(MTIMEtimestampdiff_min, "timestampdiff_min",
    1515             :           timestamp, timestamp, lng, timestampdiff_min, func2_noexcept,
    1516             :           DEC_VAR, DEC_VAR, DEC_VAR_R, DEC_INT,
    1517             :           INIT_VARIN, INIT_VARIN, INIT_VAROUT,
    1518             :           GET_NEXT_VAR, GET_NEXT_VAR, APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
    1519           1 : func2(MTIMEtimestampdiff_min_d_ts, "timestampdiff_min",
    1520             :           date, timestamp, lng, timestampdiff_min_date_timestamp, func2_noexcept,
    1521             :           DEC_VAR, DEC_VAR, DEC_VAR_R, DEC_INT,
    1522             :           INIT_VARIN, INIT_VARIN, INIT_VAROUT,
    1523             :           GET_NEXT_VAR, GET_NEXT_VAR, APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
    1524           1 : func2(MTIMEtimestampdiff_min_ts_d, "timestampdiff_min",
    1525             :           timestamp, date, lng, timestampdiff_min_timestamp_date, func2_noexcept,
    1526             :           DEC_VAR, DEC_VAR, DEC_VAR_R, DEC_INT,
    1527             :           INIT_VARIN, INIT_VARIN, INIT_VAROUT,
    1528             :           GET_NEXT_VAR, GET_NEXT_VAR, APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
    1529           2 : func2(MTIMEtimestampdiff_hour, "timestampdiff_hour",
    1530             :           timestamp, timestamp, lng, timestampdiff_hour, func2_noexcept,
    1531             :           DEC_VAR, DEC_VAR, DEC_VAR_R, DEC_INT,
    1532             :           INIT_VARIN, INIT_VARIN, INIT_VAROUT,
    1533             :           GET_NEXT_VAR, GET_NEXT_VAR, APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
    1534           1 : func2(MTIMEtimestampdiff_hour_d_ts, "timestampdiff_hour",
    1535             :           date, timestamp, lng, timestampdiff_hour_date_timestamp, func2_noexcept,
    1536             :           DEC_VAR, DEC_VAR, DEC_VAR_R, DEC_INT,
    1537             :           INIT_VARIN, INIT_VARIN, INIT_VAROUT,
    1538             :           GET_NEXT_VAR, GET_NEXT_VAR, APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
    1539           1 : func2(MTIMEtimestampdiff_hour_ts_d, "timestampdiff_hour",
    1540             :           timestamp, date, lng, timestampdiff_hour_timestamp_date, func2_noexcept,
    1541             :           DEC_VAR, DEC_VAR, DEC_VAR_R, DEC_INT,
    1542             :           INIT_VARIN, INIT_VARIN, INIT_VAROUT,
    1543             :           GET_NEXT_VAR, GET_NEXT_VAR, APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
    1544           2 : func2(MTIMEtimestampdiff_day, "timestampdiff_day",
    1545             :           timestamp, timestamp, int, timestampdiff_day, func2_noexcept,
    1546             :           DEC_VAR, DEC_VAR, DEC_VAR_R, DEC_INT,
    1547             :           INIT_VARIN, INIT_VARIN, INIT_VAROUT,
    1548             :           GET_NEXT_VAR, GET_NEXT_VAR, APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
    1549           1 : func2(MTIMEtimestampdiff_day_t_ts, "timestampdiff_day",
    1550             :           daytime, timestamp, int, timestampdiff_day_time_timestamp, func2_noexcept,
    1551             :           DEC_VAR, DEC_VAR, DEC_VAR_R, DEC_INT,
    1552             :           INIT_VARIN, INIT_VARIN, INIT_VAROUT,
    1553             :           GET_NEXT_VAR, GET_NEXT_VAR, APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
    1554           1 : func2(MTIMEtimestampdiff_day_ts_t, "timestampdiff_day",
    1555             :           timestamp, daytime, int, timestampdiff_day_timestamp_time, func2_noexcept,
    1556             :           DEC_VAR, DEC_VAR, DEC_VAR_R, DEC_INT,
    1557             :           INIT_VARIN, INIT_VARIN, INIT_VAROUT,
    1558             :           GET_NEXT_VAR, GET_NEXT_VAR, APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
    1559           2 : func2(MTIMEtimestampdiff_week, "timestampdiff_week",
    1560             :           timestamp, timestamp, int, timestampdiff_week, func2_noexcept,
    1561             :           DEC_VAR, DEC_VAR, DEC_VAR_R, DEC_INT,
    1562             :           INIT_VARIN, INIT_VARIN, INIT_VAROUT,
    1563             :           GET_NEXT_VAR, GET_NEXT_VAR, APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
    1564           0 : func2(MTIMEtimestampdiff_week_t_ts, "timestampdiff_week",
    1565             :           daytime, timestamp, int, timestampdiff_week_time_timestamp,
    1566             :           func2_noexcept, DEC_VAR, DEC_VAR, DEC_VAR_R, DEC_INT, INIT_VARIN,
    1567             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR, GET_NEXT_VAR, APPEND_VAR,
    1568             :           FINISH_INT_SINGLE, CLEAR_NOTHING)
    1569           2 : func2(MTIMEtimestampdiff_week_ts_t, "timestampdiff_week", timestamp,
    1570             :           daytime, int, timestampdiff_week_timestamp_time, func2_noexcept, DEC_VAR,
    1571             :           DEC_VAR, DEC_VAR_R, DEC_INT, INIT_VARIN, INIT_VARIN, INIT_VAROUT,
    1572             :           GET_NEXT_VAR, GET_NEXT_VAR, APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
    1573           3 : func2(MTIMEtimestampdiff_month, "timestampdiff_month", timestamp, timestamp,
    1574             :           int, timestampdiff_month, func2_noexcept, DEC_VAR, DEC_VAR, DEC_VAR_R,
    1575             :           DEC_INT, INIT_VARIN, INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR, GET_NEXT_VAR,
    1576             :           APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
    1577           1 : func2(MTIMEtimestampdiff_month_t_ts, "timestampdiff_month",
    1578             :           daytime, timestamp, int, timestampdiff_month_time_timestamp,
    1579             :           func2_noexcept, DEC_VAR, DEC_VAR, DEC_VAR_R, DEC_INT, INIT_VARIN,
    1580             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR, GET_NEXT_VAR, APPEND_VAR,
    1581             :           FINISH_INT_SINGLE, CLEAR_NOTHING)
    1582           1 : func2(MTIMEtimestampdiff_month_ts_t, "timestampdiff_month",
    1583             :           timestamp, daytime, int, timestampdiff_month_timestamp_time,
    1584             :           func2_noexcept, DEC_VAR, DEC_VAR, DEC_VAR_R, DEC_INT, INIT_VARIN,
    1585             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR, GET_NEXT_VAR, APPEND_VAR,
    1586             :           FINISH_INT_SINGLE, CLEAR_NOTHING)
    1587           3 : func2(MTIMEtimestampdiff_quarter, "timestampdiff_quarter", timestamp, timestamp,
    1588             :           int, timestampdiff_quarter, func2_noexcept, DEC_VAR, DEC_VAR, DEC_VAR_R,
    1589             :           DEC_INT, INIT_VARIN, INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR, GET_NEXT_VAR,
    1590             :           APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
    1591           1 : func2(MTIMEtimestampdiff_quarter_t_ts, "timestampdiff_quarter",
    1592             :           daytime, timestamp, int, timestampdiff_quarter_time_timestamp,
    1593             :           func2_noexcept, DEC_VAR, DEC_VAR, DEC_VAR_R, DEC_INT, INIT_VARIN,
    1594             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR, GET_NEXT_VAR, APPEND_VAR,
    1595             :           FINISH_INT_SINGLE, CLEAR_NOTHING)
    1596           1 : func2(MTIMEtimestampdiff_quarter_ts_t, "timestampdiff_quarter",
    1597             :           timestamp, daytime, int, timestampdiff_quarter_timestamp_time,
    1598             :           func2_noexcept, DEC_VAR, DEC_VAR, DEC_VAR_R, DEC_INT, INIT_VARIN,
    1599             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR, GET_NEXT_VAR, APPEND_VAR,
    1600             :           FINISH_INT_SINGLE, CLEAR_NOTHING)
    1601           2 : func2(MTIMEtimestampdiff_year, "timestampdiff_year", timestamp, timestamp, int,
    1602             :           timestampdiff_year, func2_noexcept, DEC_VAR, DEC_VAR, DEC_VAR_R, DEC_INT,
    1603             :           INIT_VARIN, INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR, GET_NEXT_VAR,
    1604             :           APPEND_VAR, FINISH_INT_SINGLE, CLEAR_NOTHING)
    1605           1 : func2(MTIMEtimestampdiff_year_t_ts, "timestampdiff_year",
    1606             :           daytime, timestamp, int, timestampdiff_year_time_timestamp,
    1607             :           func2_noexcept, DEC_VAR, DEC_VAR, DEC_VAR_R, DEC_INT, INIT_VARIN,
    1608             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR, GET_NEXT_VAR, APPEND_VAR,
    1609             :           FINISH_INT_SINGLE, CLEAR_NOTHING)
    1610           1 : func2(MTIMEtimestampdiff_year_ts_t, "timestampdiff_year",
    1611             :           timestamp, daytime, int, timestampdiff_year_timestamp_time,
    1612             :           func2_noexcept, DEC_VAR, DEC_VAR, DEC_VAR_R, DEC_INT, INIT_VARIN,
    1613             :           INIT_VARIN, INIT_VAROUT, GET_NEXT_VAR, GET_NEXT_VAR, APPEND_VAR,
    1614             :           FINISH_INT_SINGLE, CLEAR_NOTHING)
    1615             : 
    1616             : #include "mel.h"
    1617             : static mel_func mtime_init_funcs[] = {
    1618             :  command("mtime", "epoch", MTIMEseconds_since_epoch, false, "unix-time (epoch) support: seconds since epoch", args(1,2, arg("",int),arg("t",timestamp))),
    1619             :  pattern("batmtime", "epoch", MTIMEseconds_since_epoch_bulk, false, "", args(1,2, batarg("",int),batarg("t",timestamp))),
    1620             :  pattern("batmtime", "epoch", MTIMEseconds_since_epoch_bulk, false, "", args(1,3, batarg("",int),batarg("t",timestamp),batarg("s",oid))),
    1621             :  command("mtime", "epoch", MTIMEtimestamp_fromsecond_epoch, false, "convert seconds since epoch into a timestamp", args(1,2, arg("",timestamp),arg("t",int))),
    1622             :  pattern("batmtime", "epoch", MTIMEtimestamp_fromsecond_epoch_bulk, false, "", args(1,2, batarg("",timestamp),batarg("t",int))),
    1623             :  pattern("batmtime", "epoch", MTIMEtimestamp_fromsecond_epoch_bulk, false, "", args(1,3, batarg("",timestamp),batarg("t",int),batarg("s",oid))),
    1624             :  command("mtime", "epoch", MTIMEtimestamp_frommsec_epoch, false, "convert milliseconds since epoch into a timestamp", args(1,2, arg("",timestamp),arg("t",lng))),
    1625             :  pattern("batmtime", "epoch", MTIMEtimestamp_frommsec_epoch_bulk, false, "", args(1,2, batarg("",timestamp),batarg("t",lng))),
    1626             :  pattern("batmtime", "epoch", MTIMEtimestamp_frommsec_epoch_bulk, false, "", args(1,3, batarg("",timestamp),batarg("t",lng),batarg("s",oid))),
    1627             :  command("mtime", "date_sub_msec_interval", MTIMEdate_sub_msec_interval, false, "", args(1,3, arg("",date),arg("t",date),arg("ms",lng))),
    1628             :  pattern("batmtime", "date_sub_msec_interval", MTIMEdate_sub_msec_interval_bulk, false, "", args(1,3, batarg("",date),batarg("t",date),batarg("ms",lng))),
    1629             :  pattern("batmtime", "date_sub_msec_interval", MTIMEdate_sub_msec_interval_bulk_p1, false, "", args(1,3, batarg("",date),arg("t",date),batarg("ms",lng))),
    1630             :  pattern("batmtime", "date_sub_msec_interval", MTIMEdate_sub_msec_interval_bulk_p2, false, "", args(1,3, batarg("",date),batarg("t",date),arg("ms",lng))),
    1631             :  pattern("batmtime", "date_sub_msec_interval", MTIMEdate_sub_msec_interval_bulk, false, "", args(1,5, batarg("",date),batarg("t",date),batarg("ms",lng),batarg("s1",oid),batarg("s2",oid))),
    1632             :  pattern("batmtime", "date_sub_msec_interval", MTIMEdate_sub_msec_interval_bulk_p1, false, "", args(1,4, batarg("",date),arg("t",date),batarg("ms",lng),batarg("s",oid))),
    1633             :  pattern("batmtime", "date_sub_msec_interval", MTIMEdate_sub_msec_interval_bulk_p2, false, "", args(1,4, batarg("",date),batarg("t",date),arg("ms",lng),batarg("s",oid))),
    1634             :  command("mtime", "date_add_msec_interval", MTIMEdate_add_msec_interval, false, "", args(1,3, arg("",date),arg("t",date),arg("ms",lng))),
    1635             :  pattern("batmtime", "date_add_msec_interval", MTIMEdate_add_msec_interval_bulk, false, "", args(1,3, batarg("",date),batarg("t",date),batarg("ms",lng))),
    1636             :  pattern("batmtime", "date_add_msec_interval", MTIMEdate_add_msec_interval_bulk_p1, false, "", args(1,3, batarg("",date),arg("t",date),batarg("ms",lng))),
    1637             :  pattern("batmtime", "date_add_msec_interval", MTIMEdate_add_msec_interval_bulk_p2, false, "", args(1,3, batarg("",date),batarg("t",date),arg("ms",lng))),
    1638             :  pattern("batmtime", "date_add_msec_interval", MTIMEdate_add_msec_interval_bulk, false, "", args(1,5, batarg("",date),batarg("t",date),batarg("ms",lng),batarg("s1",oid),batarg("s2",oid))),
    1639             :  pattern("batmtime", "date_add_msec_interval", MTIMEdate_add_msec_interval_bulk_p1, false, "", args(1,4, batarg("",date),arg("t",date),batarg("ms",lng),batarg("s",oid))),
    1640             :  pattern("batmtime", "date_add_msec_interval", MTIMEdate_add_msec_interval_bulk_p2, false, "", args(1,4, batarg("",date),batarg("t",date),arg("ms",lng),batarg("s",oid))),
    1641             :  command("mtime", "timestamp_sub_msec_interval", MTIMEtimestamp_sub_msec_interval, false, "", args(1,3, arg("",timestamp),arg("t",timestamp),arg("ms",lng))),
    1642             :  pattern("batmtime", "timestamp_sub_msec_interval", MTIMEtimestamp_sub_msec_interval_bulk, false, "", args(1,3, batarg("",timestamp),batarg("t",timestamp),batarg("ms",lng))),
    1643             :  pattern("batmtime", "timestamp_sub_msec_interval", MTIMEtimestamp_sub_msec_interval_bulk_p1, false, "", args(1,3, batarg("",timestamp),arg("t",timestamp),batarg("ms",lng))),
    1644             :  pattern("batmtime", "timestamp_sub_msec_interval", MTIMEtimestamp_sub_msec_interval_bulk_p2, false, "", args(1,3, batarg("",timestamp),batarg("t",timestamp),arg("ms",lng))),
    1645             :  pattern("batmtime", "timestamp_sub_msec_interval", MTIMEtimestamp_sub_msec_interval_bulk, false, "", args(1,5, batarg("",timestamp),batarg("t",timestamp),batarg("ms",lng),batarg("s1",oid),batarg("s2",oid))),
    1646             :  pattern("batmtime", "timestamp_sub_msec_interval", MTIMEtimestamp_sub_msec_interval_bulk_p1, false, "", args(1,4, batarg("",timestamp),arg("t",timestamp),batarg("ms",lng),batarg("s",oid))),
    1647             :  pattern("batmtime", "timestamp_sub_msec_interval", MTIMEtimestamp_sub_msec_interval_bulk_p2, false, "", args(1,4, batarg("",timestamp),batarg("t",timestamp),arg("ms",lng),batarg("s",oid))),
    1648             :  command("mtime", "timestamp_add_msec_interval", MTIMEtimestamp_add_msec_interval, false, "", args(1,3, arg("",timestamp),arg("t",timestamp),arg("ms",lng))),
    1649             :  pattern("batmtime", "timestamp_add_msec_interval", MTIMEtimestamp_add_msec_interval_bulk, false, "", args(1,3, batarg("",timestamp),batarg("t",timestamp),batarg("ms",lng))),
    1650             :  pattern("batmtime", "timestamp_add_msec_interval", MTIMEtimestamp_add_msec_interval_bulk_p1, false, "", args(1,3, batarg("",timestamp),arg("t",timestamp),batarg("ms",lng))),
    1651             :  pattern("batmtime", "timestamp_add_msec_interval", MTIMEtimestamp_add_msec_interval_bulk_p2, false, "", args(1,3, batarg("",timestamp),batarg("t",timestamp),arg("ms",lng))),
    1652             :  pattern("batmtime", "timestamp_add_msec_interval", MTIMEtimestamp_add_msec_interval_bulk, false, "", args(1,5, batarg("",timestamp),batarg("t",timestamp),batarg("ms",lng),batarg("s1",oid),batarg("s2",oid))),
    1653             :  pattern("batmtime", "timestamp_add_msec_interval", MTIMEtimestamp_add_msec_interval_bulk_p1, false, "", args(1,4, batarg("",timestamp),arg("t",timestamp),batarg("ms",lng),batarg("s",oid))),
    1654             :  pattern("batmtime", "timestamp_add_msec_interval", MTIMEtimestamp_add_msec_interval_bulk_p2, false, "", args(1,4, batarg("",timestamp),batarg("t",timestamp),arg("ms",lng),batarg("s",oid))),
    1655             :  command("mtime", "timestamp_sub_month_interval", MTIMEtimestamp_sub_month_interval, false, "Subtract months from a timestamp", args(1,3, arg("",timestamp),arg("t",timestamp),arg("s",int))),
    1656             :  pattern("batmtime", "timestamp_sub_month_interval", MTIMEtimestamp_sub_month_interval_bulk, false, "", args(1,3, batarg("",timestamp),batarg("t",timestamp),batarg("s",int))),
    1657             :  pattern("batmtime", "timestamp_sub_month_interval", MTIMEtimestamp_sub_month_interval_bulk_p1, false, "", args(1,3, batarg("",timestamp),arg("t",timestamp),batarg("s",int))),
    1658             :  pattern("batmtime", "timestamp_sub_month_interval", MTIMEtimestamp_sub_month_interval_bulk_p2, false, "", args(1,3, batarg("",timestamp),batarg("t",timestamp),arg("s",int))),
    1659             :  pattern("batmtime", "timestamp_sub_month_interval", MTIMEtimestamp_sub_month_interval_bulk, false, "", args(1,5, batarg("",timestamp),batarg("t",timestamp),batarg("s",int),batarg("s1",oid),batarg("s2",oid))),
    1660             :  pattern("batmtime", "timestamp_sub_month_interval", MTIMEtimestamp_sub_month_interval_bulk_p1, false, "", args(1,4, batarg("",timestamp),arg("t",timestamp),batarg("s",int),batarg("s",oid))),
    1661             :  pattern("batmtime", "timestamp_sub_month_interval", MTIMEtimestamp_sub_month_interval_bulk_p2, false, "", args(1,4, batarg("",timestamp),batarg("t",timestamp),arg("s",int),batarg("s",oid))),
    1662             :  // --
    1663             :  command("mtime", "timestamp_add_month_interval", MTIMEtimestamp_add_month_interval, false, "Add months to a timestamp", args(1,3, arg("",timestamp),arg("t",timestamp),arg("s",int))),
    1664             :  pattern("batmtime", "timestamp_add_month_interval", MTIMEtimestamp_add_month_interval_bulk, false, "", args(1,3, batarg("",timestamp),batarg("t",timestamp),batarg("s",int))),
    1665             :  pattern("batmtime", "timestamp_add_month_interval", MTIMEtimestamp_add_month_interval_bulk_p1, false, "", args(1,3, batarg("",timestamp),arg("t",timestamp),batarg("s",int))),
    1666             :  pattern("batmtime", "timestamp_add_month_interval", MTIMEtimestamp_add_month_interval_bulk_p2, false, "", args(1,3, batarg("",timestamp),batarg("t",timestamp),arg("s",int))),
    1667             :  pattern("batmtime", "timestamp_add_month_interval", MTIMEtimestamp_add_month_interval_bulk, false, "", args(1,5, batarg("",timestamp),batarg("t",timestamp),batarg("s",int),batarg("s1",oid),batarg("s2",oid))),
    1668             :  pattern("batmtime", "timestamp_add_month_interval", MTIMEtimestamp_add_month_interval_bulk_p1, false, "", args(1,4, batarg("",timestamp),arg("t",timestamp),batarg("s",int),batarg("s",oid))),
    1669             :  pattern("batmtime", "timestamp_add_month_interval", MTIMEtimestamp_add_month_interval_bulk_p2, false, "", args(1,4, batarg("",timestamp),batarg("t",timestamp),arg("s",int),batarg("s",oid))),
    1670             : // odbc timestampadd corner cases
    1671             :  command("mtime", "odbc_timestamp_add_msec_time", MTIMEodbc_timestamp_add_msec_interval_time, false, "", args(1,3, arg("",timestamp),arg("t",daytime),arg("ms",lng))),
    1672             :  pattern("batmtime", "odbc_timestamp_add_msec_time", MTIMEodbc_timestamp_add_msec_interval_time_bulk, false, "", args(1,3, batarg("",timestamp),batarg("t",daytime),batarg("ms",lng))),
    1673             :  pattern("batmtime", "odbc_timestamp_add_msec_time", MTIMEodbc_timestamp_add_msec_interval_time_bulk_p1, false, "", args(1,3, batarg("",timestamp),arg("t",daytime),batarg("ms",lng))),
    1674             :  pattern("batmtime", "odbc_timestamp_add_msec_time", MTIMEodbc_timestamp_add_msec_interval_time_bulk_p2, false, "", args(1,3, batarg("",timestamp),batarg("t",daytime),arg("ms",lng))),
    1675             :  pattern("batmtime", "odbc_timestamp_add_msec_time", MTIMEodbc_timestamp_add_msec_interval_time_bulk, false, "", args(1,5, batarg("",timestamp),batarg("t",daytime),batarg("ms",lng),batarg("s1",oid),batarg("s2",oid))),
    1676             :  pattern("batmtime", "odbc_timestamp_add_msec_time", MTIMEodbc_timestamp_add_msec_interval_time_bulk_p1, false, "", args(1,4, batarg("",timestamp),arg("t",daytime),batarg("ms",lng),batarg("s",oid))),
    1677             :  pattern("batmtime", "odbc_timestamp_add_msec_time", MTIMEodbc_timestamp_add_msec_interval_time_bulk_p2, false, "", args(1,4, batarg("",timestamp),batarg("t",daytime),arg("ms",lng),batarg("s",oid))),
    1678             :  // --
    1679             :  command("mtime", "odbc_timestamp_add_month_time", MTIMEodbc_timestamp_add_month_interval_time, false, "Add months to a time", args(1,3, arg("",timestamp),arg("t",daytime),arg("s",int))),
    1680             :  pattern("batmtime", "odbc_timestamp_add_month_time", MTIMEodbc_timestamp_add_month_interval_time_bulk, false, "", args(1,3, batarg("",timestamp),batarg("t",daytime),batarg("s",int))),
    1681             :  pattern("batmtime", "odbc_timestamp_add_month_time", MTIMEodbc_timestamp_add_month_interval_time_bulk_p1, false, "", args(1,3, batarg("",timestamp),arg("t",daytime),batarg("s",int))),
    1682             :  pattern("batmtime", "odbc_timestamp_add_month_time", MTIMEodbc_timestamp_add_month_interval_time_bulk_p2, false, "", args(1,3, batarg("",timestamp),batarg("t",daytime),arg("s",int))),
    1683             :  pattern("batmtime", "odbc_timestamp_add_month_time", MTIMEodbc_timestamp_add_month_interval_time_bulk, false, "", args(1,5, batarg("",timestamp),batarg("t",daytime),batarg("s",int),batarg("s1",oid),batarg("s2",oid))),
    1684             :  pattern("batmtime", "odbc_timestamp_add_month_time", MTIMEodbc_timestamp_add_month_interval_time_bulk_p1, false, "", args(1,4, batarg("",timestamp),arg("t",daytime),batarg("s",int),batarg("s",oid))),
    1685             :  pattern("batmtime", "odbc_timestamp_add_month_time", MTIMEodbc_timestamp_add_month_interval_time_bulk_p2, false, "", args(1,4, batarg("",timestamp),batarg("t",daytime),arg("s",int),batarg("s",oid))),
    1686             :  // --
    1687             :  command("mtime", "odbc_timestamp_add_msec_date", MTIMEodbc_timestamp_add_msec_interval_date, false, "", args(1,3, arg("",timestamp),arg("d",date),arg("ms",lng))),
    1688             :  pattern("batmtime", "odbc_timestamp_add_msec_date", MTIMEodbc_timestamp_add_msec_interval_date_bulk, false, "", args(1,3, batarg("",timestamp),batarg("d",date),batarg("ms",lng))),
    1689             :  pattern("batmtime", "odbc_timestamp_add_msec_date", MTIMEodbc_timestamp_add_msec_interval_date_bulk_p1, false, "", args(1,3, batarg("",timestamp),arg("d",date),batarg("ms",lng))),
    1690             :  pattern("batmtime", "odbc_timestamp_add_msec_date", MTIMEodbc_timestamp_add_msec_interval_date_bulk_p2, false, "", args(1,3, batarg("",timestamp),batarg("d",date),arg("ms",lng))),
    1691             :  pattern("batmtime", "odbc_timestamp_add_msec_date", MTIMEodbc_timestamp_add_msec_interval_date_bulk, false, "", args(1,5, batarg("",timestamp),batarg("d",date),batarg("ms",lng),batarg("s1",oid),batarg("s2",oid))),
    1692             :  pattern("batmtime", "odbc_timestamp_add_msec_date", MTIMEodbc_timestamp_add_msec_interval_date_bulk_p1, false, "", args(1,4, batarg("",timestamp),arg("d",date),batarg("ms",lng),batarg("s",oid))),
    1693             :  pattern("batmtime", "odbc_timestamp_add_msec_date", MTIMEodbc_timestamp_add_msec_interval_date_bulk_p2, false, "", args(1,4, batarg("",timestamp),batarg("d",date),arg("ms",lng),batarg("s",oid))),
    1694             : // end odbc timestampadd corner cases
    1695             :  command("mtime", "time_sub_msec_interval", MTIMEtime_sub_msec_interval, false, "Subtract seconds from a time", args(1,3, arg("",daytime),arg("t",daytime),arg("ms",lng))),
    1696             :  pattern("batmtime", "time_sub_msec_interval", MTIMEtime_sub_msec_interval_bulk, false, "", args(1,3, batarg("",daytime),batarg("t",daytime),batarg("ms",lng))),
    1697             :  pattern("batmtime", "time_sub_msec_interval", MTIMEtime_sub_msec_interval_bulk_p1, false, "", args(1,3, batarg("",daytime),arg("t",daytime),batarg("ms",lng))),
    1698             :  pattern("batmtime", "time_sub_msec_interval", MTIMEtime_sub_msec_interval_bulk_p2, false, "", args(1,3, batarg("",daytime),batarg("t",daytime),arg("ms",lng))),
    1699             :  pattern("batmtime", "time_sub_msec_interval", MTIMEtime_sub_msec_interval_bulk, false, "", args(1,5, batarg("",daytime),batarg("t",daytime),batarg("ms",lng),batarg("s1",oid),batarg("s2",oid))),
    1700             :  pattern("batmtime", "time_sub_msec_interval", MTIMEtime_sub_msec_interval_bulk_p1, false, "", args(1,4, batarg("",daytime),arg("t",daytime),batarg("ms",lng),batarg("s",oid))),
    1701             :  pattern("batmtime", "time_sub_msec_interval", MTIMEtime_sub_msec_interval_bulk_p2, false, "", args(1,4, batarg("",daytime),batarg("t",daytime),arg("ms",lng),batarg("s",oid))),
    1702             :  command("mtime", "time_add_msec_interval", MTIMEtime_add_msec_interval, false, "Add seconds to a time", args(1,3, arg("",daytime),arg("t",daytime),arg("ms",lng))),
    1703             :  pattern("batmtime", "time_add_msec_interval", MTIMEtime_add_msec_interval_bulk, false, "", args(1,3, batarg("",daytime),batarg("t",daytime),batarg("ms",lng))),
    1704             :  pattern("batmtime", "time_add_msec_interval", MTIMEtime_add_msec_interval_bulk_p1, false, "", args(1,3, batarg("",daytime),arg("t",daytime),batarg("ms",lng))),
    1705             :  pattern("batmtime", "time_add_msec_interval", MTIMEtime_add_msec_interval_bulk_p2, false, "", args(1,3, batarg("",daytime),batarg("t",daytime),arg("ms",lng))),
    1706             :  pattern("batmtime", "time_add_msec_interval", MTIMEtime_add_msec_interval_bulk, false, "", args(1,5, batarg("",daytime),batarg("t",daytime),batarg("ms",lng),batarg("s1",oid),batarg("s2",oid))),
    1707             :  pattern("batmtime", "time_add_msec_interval", MTIMEtime_add_msec_interval_bulk_p1, false, "", args(1,4, batarg("",daytime),arg("t",daytime),batarg("ms",lng),batarg("s",oid))),
    1708             :  pattern("batmtime", "time_add_msec_interval", MTIMEtime_add_msec_interval_bulk_p2, false, "", args(1,4, batarg("",daytime),batarg("t",daytime),arg("ms",lng),batarg("s",oid))),
    1709             :  command("mtime", "diff", MTIMEdaytime_diff_msec, false, "returns the number of msec between 'val1' and 'val2'.", args(1,3, arg("",lng),arg("val1",daytime),arg("val2",daytime))),
    1710             :  pattern("batmtime", "diff", MTIMEdaytime_diff_msec_bulk, false, "", args(1,3, batarg("",lng),batarg("val1",daytime),batarg("val2",daytime))),
    1711             :  pattern("batmtime", "diff", MTIMEdaytime_diff_msec_bulk_p1, false, "", args(1,3, batarg("",lng),arg("val1",daytime),batarg("val2",daytime))),
    1712             :  pattern("batmtime", "diff", MTIMEdaytime_diff_msec_bulk_p2, false, "", args(1,3, batarg("",lng),batarg("val1",daytime),arg("val2",daytime))),
    1713             :  pattern("batmtime", "diff", MTIMEdaytime_diff_msec_bulk, false, "", args(1,5, batarg("",lng),batarg("val1",daytime),batarg("val2",daytime),batarg("s1",oid),batarg("s2",oid))),
    1714             :  pattern("batmtime", "diff", MTIMEdaytime_diff_msec_bulk_p1, false, "", args(1,4, batarg("",lng),arg("val1",daytime),batarg("val2",daytime),batarg("s",oid))),
    1715             :  pattern("batmtime", "diff", MTIMEdaytime_diff_msec_bulk_p2, false, "", args(1,4, batarg("",lng),batarg("val1",daytime),arg("val2",daytime),batarg("s",oid))),
    1716             :  command("mtime", "date_sub_month_interval", MTIMEdate_submonths, false, "Subtract months from a date", args(1,3, arg("",date),arg("t",date),arg("months",int))),
    1717             :  pattern("batmtime", "date_sub_month_interval", MTIMEdate_submonths_bulk, false, "", args(1,3, batarg("",date),batarg("t",date),batarg("months",int))),
    1718             :  pattern("batmtime", "date_sub_month_interval", MTIMEdate_submonths_bulk_p1, false, "", args(1,3, batarg("",date),arg("t",date),batarg("months",int))),
    1719             :  pattern("batmtime", "date_sub_month_interval", MTIMEdate_submonths_bulk_p2, false, "", args(1,3, batarg("",date),batarg("t",date),arg("months",int))),
    1720             :  pattern("batmtime", "date_sub_month_interval", MTIMEdate_submonths_bulk, false, "", args(1,5, batarg("",date),batarg("t",date),batarg("months",int),batarg("s1",oid),batarg("s2",oid))),
    1721             :  pattern("batmtime", "date_sub_month_interval", MTIMEdate_submonths_bulk_p1, false, "", args(1,4, batarg("",date),arg("t",date),batarg("months",int),batarg("s",oid))),
    1722             :  pattern("batmtime", "date_sub_month_interval", MTIMEdate_submonths_bulk_p2, false, "", args(1,4, batarg("",date),batarg("t",date),arg("months",int),batarg("s",oid))),
    1723             :  command("mtime", "local_timezone", MTIMElocal_timezone_msec, false, "get the local timezone in seconds", args(1,1, arg("",lng))),
    1724             :  command("mtime", "century", MTIMEdate_extract_century, false, "extracts century from date.", args(1,2, arg("",int),arg("d",date))),
    1725             :  pattern("batmtime", "century", MTIMEdate_extract_century_bulk, false, "", args(1,2, batarg("",int),batarg("d",date))),
    1726             :  pattern("batmtime", "century", MTIMEdate_extract_century_bulk, false, "", args(1,3, batarg("",int),batarg("d",date),batarg("s",oid))),
    1727             :  command("mtime", "decade", MTIMEdate_extract_decade, false, "extracts decade from date.", args(1,2, arg("",int),arg("d",date))),
    1728             :  pattern("batmtime", "decade", MTIMEdate_extract_decade_bulk, false, "", args(1,2, batarg("",int),batarg("d",date))),
    1729             :  pattern("batmtime", "decade", MTIMEdate_extract_decade_bulk, false, "", args(1,3, batarg("",int),batarg("d",date),batarg("s",oid))),
    1730             :  command("mtime", "year", MTIMEdate_extract_year, false, "extracts year from date.", args(1,2, arg("",int),arg("d",date))),
    1731             :  pattern("batmtime", "year", MTIMEdate_extract_year_bulk, false, "", args(1,2, batarg("",int),batarg("d",date))),
    1732             :  pattern("batmtime", "year", MTIMEdate_extract_year_bulk, false, "", args(1,3, batarg("",int),batarg("d",date),batarg("s",oid))),
    1733             :  command("mtime", "quarter", MTIMEdate_extract_quarter, false, "extracts quarter from date", args(1,2, arg("",bte),arg("d",date))),
    1734             :  pattern("batmtime", "quarter", MTIMEdate_extract_quarter_bulk, false, "", args(1,2, batarg("",bte),batarg("d",date))),
    1735             :  pattern("batmtime", "quarter", MTIMEdate_extract_quarter_bulk, false, "", args(1,3, batarg("",bte),batarg("d",date),batarg("s",oid))),
    1736             :  command("mtime", "month", MTIMEdate_extract_month, false, "extracts month from date", args(1,2, arg("",bte),arg("d",date))),
    1737             :  pattern("batmtime", "month", MTIMEdate_extract_month_bulk, false, "", args(1,2, batarg("",bte),batarg("d",date))),
    1738             :  pattern("batmtime", "month", MTIMEdate_extract_month_bulk, false, "", args(1,3, batarg("",bte),batarg("d",date),batarg("s",oid))),
    1739             :  command("mtime", "day", MTIMEdate_extract_day, false, "extracts day from date ", args(1,2, arg("",bte),arg("d",date))),
    1740             :  pattern("batmtime", "day", MTIMEdate_extract_day_bulk, false, "", args(1,2, batarg("",bte),batarg("d",date))),
    1741             :  pattern("batmtime", "day", MTIMEdate_extract_day_bulk, false, "", args(1,3, batarg("",bte),batarg("d",date),batarg("s",oid))),
    1742             :  command("mtime", "epoch_ms", MTIMEdate_extract_epoch_ms, false, "", args(1,2, arg("",lng),arg("d",date))),
    1743             :  pattern("batmtime", "epoch_ms", MTIMEdate_extract_epoch_ms_bulk, false, "", args(1,2, batarg("",lng),batarg("d",date))),
    1744             :  pattern("batmtime", "epoch_ms", MTIMEdate_extract_epoch_ms_bulk, false, "", args(1,3, batarg("",lng),batarg("d",date),batarg("s",oid))),
    1745             :  command("mtime", "hours", MTIMEdaytime_extract_hours, false, "extracts hour from daytime", args(1,2, arg("",bte),arg("h",daytime))),
    1746             :  pattern("batmtime", "hours", MTIMEdaytime_extract_hours_bulk, false, "", args(1,2, batarg("",bte),batarg("d",daytime))),
    1747             :  pattern("batmtime", "hours", MTIMEdaytime_extract_hours_bulk, false, "", args(1,3, batarg("",bte),batarg("d",daytime),batarg("s",oid))),
    1748             :  command("mtime", "minutes", MTIMEdaytime_extract_minutes, false, "extracts minutes from daytime", args(1,2, arg("",bte),arg("d",daytime))),
    1749             :  pattern("batmtime", "minutes", MTIMEdaytime_extract_minutes_bulk, false, "", args(1,2, batarg("",bte),batarg("d",daytime))),
    1750             :  pattern("batmtime", "minutes", MTIMEdaytime_extract_minutes_bulk, false, "", args(1,3, batarg("",bte),batarg("d",daytime),batarg("s",oid))),
    1751             :  command("mtime", "sql_seconds", MTIMEdaytime_extract_sql_seconds, false, "extracts seconds (with fractional milliseconds) from daytime", args(1,2, arg("",int),arg("d",daytime))),
    1752             :  pattern("batmtime", "sql_seconds", MTIMEdaytime_extract_sql_seconds_bulk, false, "", args(1,2, batarg("",int),batarg("d",daytime))),
    1753             :  pattern("batmtime", "sql_seconds", MTIMEdaytime_extract_sql_seconds_bulk, false, "", args(1,3, batarg("",int),batarg("d",daytime),batarg("s",oid))),
    1754             :  command("mtime", "epoch_ms", MTIMEdaytime_extract_epoch_ms, false, "", args(1,2, arg("",lng),arg("d",daytime))),
    1755             :  pattern("batmtime", "epoch_ms", MTIMEdaytime_extract_epoch_ms_bulk, false, "", args(1,2, batarg("",lng),batarg("d",daytime))),
    1756             :  pattern("batmtime", "epoch_ms", MTIMEdaytime_extract_epoch_ms_bulk, false, "", args(1,3, batarg("",lng),batarg("d",daytime),batarg("s",oid))),
    1757             :  command("mtime", "addmonths", MTIMEdate_addmonths, false, "returns the date after a number of\nmonths (possibly negative).", args(1,3, arg("",date),arg("value",date),arg("months",int))),
    1758             :  pattern("batmtime", "addmonths", MTIMEdate_addmonths_bulk, false, "", args(1,3, batarg("",date),batarg("value",date),batarg("months",int))),
    1759             :  pattern("batmtime", "addmonths", MTIMEdate_addmonths_bulk_p1, false, "", args(1,3, batarg("",date),arg("value",date),batarg("months",int))),
    1760             :  pattern("batmtime", "addmonths", MTIMEdate_addmonths_bulk_p2, false, "", args(1,3, batarg("",date),batarg("value",date),arg("months",int))),
    1761             :  pattern("batmtime", "addmonths", MTIMEdate_addmonths_bulk, false, "", args(1,5, batarg("",date),batarg("value",date),batarg("months",int),batarg("s1",oid),batarg("s2",oid))),
    1762             :  pattern("batmtime", "addmonths", MTIMEdate_addmonths_bulk_p1, false, "", args(1,4, batarg("",date),arg("value",date),batarg("months",int),batarg("s",oid))),
    1763             :  pattern("batmtime", "addmonths", MTIMEdate_addmonths_bulk_p2, false, "", args(1,4, batarg("",date),batarg("value",date),arg("months",int),batarg("s",oid))),
    1764             :  command("mtime", "diff", MTIMEdate_diff, false, "returns the number of days\nbetween 'val1' and 'val2'.", args(1,3, arg("",lng),arg("val1",date),arg("val2",date))),
    1765             :  pattern("batmtime", "diff", MTIMEdate_diff_bulk, false, "", args(1,3, batarg("",lng),batarg("val1",date),batarg("val2",date))),
    1766             :  pattern("batmtime", "diff", MTIMEdate_diff_bulk_p1, false, "", args(1,3, batarg("",lng),arg("val1",date),batarg("val2",date))),
    1767             :  pattern("batmtime", "diff", MTIMEdate_diff_bulk_p2, false, "", args(1,3, batarg("",lng),batarg("val1",date),arg("val2",date))),
    1768             :  pattern("batmtime", "diff", MTIMEdate_diff_bulk, false, "", args(1,5, batarg("",lng),batarg("val1",date),batarg("val2",date),batarg("s1",oid),batarg("s2",oid))),
    1769             :  pattern("batmtime", "diff", MTIMEdate_diff_bulk_p1, false, "", args(1,4, batarg("",lng),arg("val1",date),batarg("val2",date),batarg("s",oid))),
    1770             :  pattern("batmtime", "diff", MTIMEdate_diff_bulk_p2, false, "", args(1,4, batarg("",lng),batarg("val1",date),arg("val2",date),batarg("s",oid))),
    1771             :  command("mtime", "dayofyear", MTIMEdate_extract_dayofyear, false, "Returns N where d is the Nth day\nof the year (january 1 returns 1)", args(1,2, arg("",sht),arg("d",date))),
    1772             :  pattern("batmtime", "dayofyear", MTIMEdate_extract_dayofyear_bulk, false, "", args(1,2, batarg("",sht),batarg("d",date))),
    1773             :  pattern("batmtime", "dayofyear", MTIMEdate_extract_dayofyear_bulk, false, "", args(1,3, batarg("",sht),batarg("d",date),batarg("s",oid))),
    1774             :  command("mtime", "weekofyear", MTIMEdate_extract_weekofyear, false, "Returns the week number in the year.", args(1,2, arg("",bte),arg("d",date))),
    1775             :  pattern("batmtime", "weekofyear", MTIMEdate_extract_weekofyear_bulk, false, "", args(1,2, batarg("",bte),batarg("d",date))),
    1776             :  pattern("batmtime", "weekofyear", MTIMEdate_extract_weekofyear_bulk, false, "", args(1,3, batarg("",bte),batarg("d",date),batarg("s",oid))),
    1777             :  command("mtime", "usweekofyear", MTIMEdate_extract_usweekofyear, false, "Returns the week number in the year, US style.", args(1,2, arg("",bte),arg("d",date))),
    1778             :  pattern("batmtime", "usweekofyear", MTIMEdate_extract_usweekofyear_bulk, false, "", args(1,2, batarg("",bte),batarg("d",date))),
    1779             :  pattern("batmtime", "usweekofyear", MTIMEdate_extract_usweekofyear_bulk, false, "", args(1,3, batarg("",bte),batarg("d",date),batarg("s",oid))),
    1780             :  command("mtime", "dayofweek", MTIMEdate_extract_dayofweek, false, "Returns the current day of the week\nwhere 1=monday, .., 7=sunday", args(1,2, arg("",bte),arg("d",date))),
    1781             :  pattern("batmtime", "dayofweek", MTIMEdate_extract_dayofweek_bulk, false, "", args(1,2, batarg("",bte),batarg("d",date))),
    1782             :  pattern("batmtime", "dayofweek", MTIMEdate_extract_dayofweek_bulk, false, "", args(1,3, batarg("",bte),batarg("d",date),batarg("s",oid))),
    1783             :  command("mtime", "diff", MTIMEtimestamp_diff_msec, false, "returns the number of milliseconds\nbetween 'val1' and 'val2'.", args(1,3, arg("",lng),arg("val1",timestamp),arg("val2",timestamp))),
    1784             :  pattern("batmtime", "diff", MTIMEtimestamp_diff_msec_bulk, false, "", args(1,3, batarg("",lng),batarg("val1",timestamp),batarg("val2",timestamp))),
    1785             :  pattern("batmtime", "diff", MTIMEtimestamp_diff_msec_bulk_p1, false, "", args(1,3, batarg("",lng),arg("val1",timestamp),batarg("val2",timestamp))),
    1786             :  pattern("batmtime", "diff", MTIMEtimestamp_diff_msec_bulk_p2, false, "", args(1,3, batarg("",lng),batarg("val1",timestamp),arg("val2",timestamp))),
    1787             :  pattern("batmtime", "diff", MTIMEtimestamp_diff_msec_bulk, false, "", args(1,5, batarg("",lng),batarg("val1",timestamp),batarg("val2",timestamp),batarg("s1",oid),batarg("s2",oid))),
    1788             :  pattern("batmtime", "diff", MTIMEtimestamp_diff_msec_bulk_p1, false, "", args(1,4, batarg("",lng),arg("val1",timestamp),batarg("val2",timestamp),batarg("s",oid))),
    1789             :  pattern("batmtime", "diff", MTIMEtimestamp_diff_msec_bulk_p2, false, "", args(1,4, batarg("",lng),batarg("val1",timestamp),arg("val2",timestamp),batarg("s",oid))),
    1790             :  command("mtime", "str_to_date", MTIMEstr_to_date, false, "create a date from the string, using the specified format (see man strptime)", args(1,4, arg("",date),arg("s",str),arg("format",str),arg("tz_msec",lng))),
    1791             :  pattern("batmtime", "str_to_date", MTIMEstr_to_date_bulk, false, "", args(1,4, batarg("",date),batarg("s",str),batarg("format",str),arg("tz_msec",lng))),
    1792             :  pattern("batmtime", "str_to_date", MTIMEstr_to_date_bulk_p1, false, "", args(1,4, batarg("",date),arg("s",str),batarg("format",str),arg("tz_msec",lng))),
    1793             :  pattern("batmtime", "str_to_date", MTIMEstr_to_date_bulk_p2, false, "", args(1,4, batarg("",date),batarg("s",str),arg("format",str),arg("tz_msec",lng))),
    1794             :  pattern("batmtime", "str_to_date", MTIMEstr_to_date_bulk, false, "", args(1,6, batarg("",date),batarg("s",str),batarg("format",str),batarg("s1",oid),batarg("s2",oid),arg("tz_msec",lng))),
    1795             :  pattern("batmtime", "str_to_date", MTIMEstr_to_date_bulk_p1, false, "", args(1,5, batarg("",date),arg("s",str),batarg("format",str),batarg("s",oid),arg("tz_msec",lng))),
    1796             :  pattern("batmtime", "str_to_date", MTIMEstr_to_date_bulk_p2, false, "", args(1,5, batarg("",date),batarg("s",str),arg("format",str),batarg("s",oid),arg("tz_msec",lng))),
    1797             :  command("mtime", "date_to_str", MTIMEdate_to_str, false, "create a string from the date, using the specified format (see man strftime)", args(1,3, arg("",str),arg("d",date),arg("format",str))),
    1798             :  pattern("batmtime", "date_to_str", MTIMEdate_to_str_bulk, false, "", args(1,3, batarg("",str),batarg("d",date),batarg("format",str))),
    1799             :  pattern("batmtime", "date_to_str", MTIMEdate_to_str_bulk_p1, false, "", args(1,3, batarg("",str),arg("d",date),batarg("format",str))),
    1800             :  pattern("batmtime", "date_to_str", MTIMEdate_to_str_bulk_p2, false, "", args(1,3, batarg("",str),batarg("d",date),arg("format",str))),
    1801             :  pattern("batmtime", "date_to_str", MTIMEdate_to_str_bulk, false, "", args(1,5, batarg("",str),batarg("d",date),batarg("format",str),batarg("s1",oid),batarg("s2",oid))),
    1802             :  pattern("batmtime", "date_to_str", MTIMEdate_to_str_bulk_p1, false, "", args(1,4, batarg("",str),arg("d",date),batarg("format",str),batarg("s",oid))),
    1803             :  pattern("batmtime", "date_to_str", MTIMEdate_to_str_bulk_p2, false, "", args(1,4, batarg("",str),batarg("d",date),arg("format",str),batarg("s",oid))),
    1804             :  command("mtime", "str_to_time", MTIMEstr_to_time, false, "create a time from the string, using the specified format (see man strptime)", args(1,4, arg("",daytime),arg("s",str),arg("format",str),arg("tz_msec",lng))),
    1805             :  pattern("batmtime", "str_to_time", MTIMEstr_to_time_bulk, false, "", args(1,4, batarg("",daytime),batarg("s",str),batarg("format",str),arg("tz_msec",lng))),
    1806             :  pattern("batmtime", "str_to_time", MTIMEstr_to_time_bulk_p1, false, "", args(1,4, batarg("",daytime),arg("s",str),batarg("format",str),arg("tz_msec",lng))),
    1807             :  pattern("batmtime", "str_to_time", MTIMEstr_to_time_bulk_p2, false, "", args(1,4, batarg("",daytime),batarg("s",str),arg("format",str),arg("tz_msec",lng))),
    1808             :  pattern("batmtime", "str_to_time", MTIMEstr_to_time_bulk, false, "", args(1,6, batarg("",daytime),batarg("s",str),batarg("format",str),batarg("s1",oid),batarg("s2",oid),arg("tz_msec",lng))),
    1809             :  pattern("batmtime", "str_to_time", MTIMEstr_to_time_bulk_p1, false, "", args(1,5, batarg("",daytime),arg("s",str),batarg("format",str),batarg("s",oid),arg("tz_msec",lng))),
    1810             :  pattern("batmtime", "str_to_time", MTIMEstr_to_time_bulk_p2, false, "", args(1,5, batarg("",daytime),batarg("s",str),arg("format",str),batarg("s",oid),arg("tz_msec",lng))),
    1811             :  command("mtime", "time_to_str", MTIMEtime_to_str, false, "create a string from the time, using the specified format (see man strftime)", args(1,3, arg("",str),arg("d",daytime),arg("format",str))),
    1812             :  pattern("batmtime", "time_to_str", MTIMEtime_to_str_bulk, false, "", args(1,3, batarg("",str),batarg("d",daytime),batarg("format",str))),
    1813             :  pattern("batmtime", "time_to_str", MTIMEtime_to_str_bulk_p1, false, "", args(1,3, batarg("",str),arg("d",daytime),batarg("format",str))),
    1814             :  pattern("batmtime", "time_to_str", MTIMEtime_to_str_bulk_p2, false, "", args(1,3, batarg("",str),batarg("d",daytime),arg("format",str))),
    1815             :  pattern("batmtime", "time_to_str", MTIMEtime_to_str_bulk, false, "", args(1,5, batarg("",str),batarg("d",daytime),batarg("format",str),batarg("s1",oid),batarg("s2",oid))),
    1816             :  pattern("batmtime", "time_to_str", MTIMEtime_to_str_bulk_p1, false, "", args(1,4, batarg("",str),arg("d",daytime),batarg("format",str),batarg("s",oid))),
    1817             :  pattern("batmtime", "time_to_str", MTIMEtime_to_str_bulk_p2, false, "", args(1,4, batarg("",str),batarg("d",daytime),arg("format",str),batarg("s",oid))),
    1818             :  command("mtime", "timetz_to_str", MTIMEtimetz_to_str, false, "create a string from the time, using the specified format (see man strftime)", args(1,4, arg("",str),arg("d",daytime),arg("format",str),arg("tz_msec",lng))),
    1819             :  pattern("batmtime", "timetz_to_str", MTIMEtimetz_to_str_bulk, false, "", args(1,4, batarg("",str),batarg("d",daytime),batarg("format",str),arg("tz_msec",lng))),
    1820             :  pattern("batmtime", "timetz_to_str", MTIMEtimetz_to_str_bulk_p1, false, "", args(1,4, batarg("",str),arg("d",daytime),batarg("format",str),arg("tz_msec",lng))),
    1821             :  pattern("batmtime", "timetz_to_str", MTIMEtimetz_to_str_bulk_p2, false, "", args(1,4, batarg("",str),batarg("d",daytime),arg("format",str),arg("tz_msec",lng))),
    1822             :  pattern("batmtime", "timetz_to_str", MTIMEtimetz_to_str_bulk, false, "", args(1,6, batarg("",str),batarg("d",daytime),batarg("format",str),batarg("s1",oid),batarg("s2",oid),arg("tz_msec",lng))),
    1823             :  pattern("batmtime", "timetz_to_str", MTIMEtimetz_to_str_bulk_p1, false, "", args(1,5, batarg("",str),arg("d",daytime),batarg("format",str),batarg("s",oid),arg("tz_msec",lng))),
    1824             :  pattern("batmtime", "timetz_to_str", MTIMEtimetz_to_str_bulk_p2, false, "", args(1,5, batarg("",str),batarg("d",daytime),arg("format",str),batarg("s",oid),arg("tz_msec",lng))),
    1825             :  command("mtime", "str_to_timestamp", MTIMEstr_to_timestamp, false, "create a timestamp from the string, using the specified format (see man strptime)", args(1,4, arg("",timestamp),arg("s",str),arg("format",str),arg("tz_msec",lng))),
    1826             :  pattern("batmtime", "str_to_timestamp", MTIMEstr_to_timestamp_bulk, false, "", args(1,4, batarg("",timestamp),batarg("d",str),batarg("format",str),arg("tz_msec",lng))),
    1827             :  pattern("batmtime", "str_to_timestamp", MTIMEstr_to_timestamp_bulk_p1, false, "", args(1,4, batarg("",timestamp),arg("s",str),batarg("format",str),arg("tz_msec",lng))),
    1828             :  pattern("batmtime", "str_to_timestamp", MTIMEstr_to_timestamp_bulk_p2, false, "", args(1,4, batarg("",timestamp),batarg("s",str),arg("format",str),arg("tz_msec",lng))),
    1829             :  pattern("batmtime", "str_to_timestamp", MTIMEstr_to_timestamp_bulk, false, "", args(1,6, batarg("",timestamp),batarg("d",str),batarg("format",str),batarg("s1",oid),batarg("s2",oid),arg("tz_msec",lng))),
    1830             :  pattern("batmtime", "str_to_timestamp", MTIMEstr_to_timestamp_bulk_p1, false, "", args(1,5, batarg("",timestamp),arg("s",str),batarg("format",str),batarg("s",oid),arg("tz_msec",lng))),
    1831             :  pattern("batmtime", "str_to_timestamp", MTIMEstr_to_timestamp_bulk_p2, false, "", args(1,5, batarg("",timestamp),batarg("s",str),arg("format",str),batarg("s",oid),arg("tz_msec",lng))),
    1832             :  command("mtime", "timestamp_to_str", MTIMEtimestamp_to_str, false, "create a string from the time, using the specified format (see man strftime)", args(1,3, arg("",str),arg("d",timestamp),arg("format",str))),
    1833             :  pattern("batmtime", "timestamp_to_str", MTIMEtimestamp_to_str_bulk, false, "", args(1,3, batarg("",str),batarg("d",timestamp),batarg("format",str))),
    1834             :  pattern("batmtime", "timestamp_to_str", MTIMEtimestamp_to_str_bulk_p1, false, "", args(1,3, batarg("",str),arg("d",timestamp),batarg("format",str))),
    1835             :  pattern("batmtime", "timestamp_to_str", MTIMEtimestamp_to_str_bulk_p2, false, "", args(1,3, batarg("",str),batarg("d",timestamp),arg("format",str))),
    1836             :  pattern("batmtime", "timestamp_to_str", MTIMEtimestamp_to_str_bulk, false, "", args(1,5, batarg("",str),batarg("d",timestamp),batarg("format",str),batarg("s1",oid),batarg("s2",oid))),
    1837             :  pattern("batmtime", "timestamp_to_str", MTIMEtimestamp_to_str_bulk_p1, false, "", args(1,4, batarg("",str),arg("d",timestamp),batarg("format",str),batarg("s",oid))),
    1838             :  pattern("batmtime", "timestamp_to_str", MTIMEtimestamp_to_str_bulk_p2, false, "", args(1,4, batarg("",str),batarg("d",timestamp),arg("format",str),batarg("s",oid))),
    1839             :  command("mtime", "timestamptz_to_str", MTIMEtimestamptz_to_str, false, "create a string from the time, using the specified format (see man strftime)", args(1,4, arg("",str),arg("d",timestamp),arg("format",str),arg("tz_msec",lng))),
    1840             :  pattern("batmtime", "timestamptz_to_str", MTIMEtimestamptz_to_str_bulk, false, "", args(1,4, batarg("",str),batarg("d",timestamp),batarg("format",str),arg("tz_msec",lng))),
    1841             :  pattern("batmtime", "timestamptz_to_str", MTIMEtimestamptz_to_str_bulk_p1, false, "", args(1,4, batarg("",str),arg("d",timestamp),batarg("format",str),arg("tz_msec",lng))),
    1842             :  pattern("batmtime", "timestamptz_to_str", MTIMEtimestamptz_to_str_bulk_p2, false, "", args(1,4, batarg("",str),batarg("d",timestamp),arg("format",str),arg("tz_msec",lng))),
    1843             :  pattern("batmtime", "timestamptz_to_str", MTIMEtimestamptz_to_str_bulk, false, "", args(1,6, batarg("",str),batarg("d",timestamp),batarg("format",str),batarg("s1",oid),batarg("s2",oid),arg("tz_msec",lng))),
    1844             :  pattern("batmtime", "timestamptz_to_str", MTIMEtimestamptz_to_str_bulk_p1, false, "", args(1,5, batarg("",str),arg("d",timestamp),batarg("format",str),batarg("s",oid),arg("tz_msec",lng))),
    1845             :  pattern("batmtime", "timestamptz_to_str", MTIMEtimestamptz_to_str_bulk_p2, false, "", args(1,5, batarg("",str),batarg("d",timestamp),arg("format",str),batarg("s",oid),arg("tz_msec",lng))),
    1846             :  command("mtime", "current_timestamp", MTIMEcurrent_timestamp, false, "", args(1,1, arg("",timestamp))),
    1847             :  command("mtime", "current_date", MTIMEcurrent_date, false, "", args(1,1, arg("",date))),
    1848             :  command("mtime", "current_time", MTIMEcurrent_time, false, "", args(1,1, arg("",daytime))),
    1849             :  command("mtime", "century", MTIMEtimestamp_century, false, "", args(1,2, arg("",int),arg("t",timestamp))),
    1850             :  pattern("batmtime", "century", MTIMEtimestamp_century_bulk, false, "", args(1,2, batarg("",int),batarg("t",timestamp))),
    1851             :  pattern("batmtime", "century", MTIMEtimestamp_century_bulk, false, "", args(1,3, batarg("",int),batarg("t",timestamp),batarg("s",oid))),
    1852             :  command("mtime", "decade", MTIMEtimestamp_decade, false, "", args(1,2, arg("",int),arg("t",timestamp))),
    1853             :  pattern("batmtime", "decade", MTIMEtimestamp_decade_bulk, false, "", args(1,2, batarg("",int),batarg("t",timestamp))),
    1854             :  pattern("batmtime", "decade", MTIMEtimestamp_decade_bulk, false, "", args(1,3, batarg("",int),batarg("t",timestamp),batarg("s",oid))),
    1855             :  command("mtime", "year", MTIMEtimestamp_year, false, "", args(1,2, arg("",int),arg("t",timestamp))),
    1856             :  pattern("batmtime", "year", MTIMEtimestamp_year_bulk, false, "", args(1,2, batarg("",int),batarg("t",timestamp))),
    1857             :  pattern("batmtime", "year", MTIMEtimestamp_year_bulk, false, "", args(1,3, batarg("",int),batarg("t",timestamp),batarg("s",oid))),
    1858             :  command("mtime", "quarter", MTIMEtimestamp_quarter, false, "", args(1,2, arg("",bte),arg("t",timestamp))),
    1859             :  pattern("batmtime", "quarter", MTIMEtimestamp_quarter_bulk, false, "", args(1,2, batarg("",bte),batarg("t",timestamp))),
    1860             :  pattern("batmtime", "quarter", MTIMEtimestamp_quarter_bulk, false, "", args(1,3, batarg("",bte),batarg("t",timestamp),batarg("s",oid))),
    1861             :  command("mtime", "month", MTIMEtimestamp_month, false, "", args(1,2, arg("",bte),arg("t",timestamp))),
    1862             :  pattern("batmtime", "month", MTIMEtimestamp_month_bulk, false, "", args(1,2, batarg("",bte),batarg("t",timestamp))),
    1863             :  pattern("batmtime", "month", MTIMEtimestamp_month_bulk, false, "", args(1,3, batarg("",bte),batarg("t",timestamp),batarg("s",oid))),
    1864             :  command("mtime", "day", MTIMEtimestamp_day, false, "", args(1,2, arg("",bte),arg("t",timestamp))),
    1865             :  pattern("batmtime", "day", MTIMEtimestamp_day_bulk, false, "", args(1,2, batarg("",bte),batarg("t",timestamp))),
    1866             :  pattern("batmtime", "day", MTIMEtimestamp_day_bulk, false, "", args(1,3, batarg("",bte),batarg("t",timestamp),batarg("s",oid))),
    1867             :  command("mtime", "hours", MTIMEtimestamp_hours, false, "", args(1,2, arg("",bte),arg("t",timestamp))),
    1868             :  pattern("batmtime", "hours", MTIMEtimestamp_hours_bulk, false, "", args(1,2, batarg("",bte),batarg("t",timestamp))),
    1869             :  pattern("batmtime", "hours", MTIMEtimestamp_hours_bulk, false, "", args(1,3, batarg("",bte),batarg("t",timestamp),batarg("s",oid))),
    1870             :  command("mtime", "minutes", MTIMEtimestamp_minutes, false, "", args(1,2, arg("",bte),arg("t",timestamp))),
    1871             :  pattern("batmtime", "minutes", MTIMEtimestamp_minutes_bulk, false, "", args(1,2, batarg("",bte),batarg("t",timestamp))),
    1872             :  pattern("batmtime", "minutes", MTIMEtimestamp_minutes_bulk, false, "", args(1,3, batarg("",bte),batarg("t",timestamp),batarg("s",oid))),
    1873             :  command("mtime", "sql_seconds", MTIMEtimestamp_sql_seconds, false, "", args(1,2, arg("",int),arg("t",timestamp))),
    1874             :  pattern("batmtime", "sql_seconds", MTIMEtimestamp_sql_seconds_bulk, false, "", args(1,2, batarg("",int),batarg("d",timestamp))),
    1875             :  pattern("batmtime", "sql_seconds", MTIMEtimestamp_sql_seconds_bulk, false, "", args(1,3, batarg("",int),batarg("d",timestamp),batarg("s",oid))),
    1876             :  command("mtime", "epoch_ms", MTIMEtimestamp_extract_epoch_ms, false, "", args(1,2, arg("",lng),arg("t",timestamp))),
    1877             :  pattern("batmtime", "epoch_ms", MTIMEtimestamp_extract_epoch_ms_bulk, false, "", args(1,2, batarg("",lng),batarg("t",timestamp))),
    1878             :  pattern("batmtime", "epoch_ms", MTIMEtimestamp_extract_epoch_ms_bulk, false, "", args(1,3, batarg("",lng),batarg("t",timestamp),batarg("s",oid))),
    1879             :  command("mtime", "year", MTIMEsql_year, false, "", args(1,2, arg("",int),arg("months",int))),
    1880             :  pattern("batmtime", "year", MTIMEsql_year_bulk, false, "", args(1,2, batarg("",int),batarg("months",int))),
    1881             :  pattern("batmtime", "year", MTIMEsql_year_bulk, false, "", args(1,3, batarg("",int),batarg("months",int),batarg("s",oid))),
    1882             :  command("mtime", "month", MTIMEsql_month, false, "", args(1,2, arg("",int),arg("months",int))),
    1883             :  pattern("batmtime", "month", MTIMEsql_month_bulk, false, "", args(1,2, batarg("",int),batarg("months",int))),
    1884             :  pattern("batmtime", "month", MTIMEsql_month_bulk, false, "", args(1,3, batarg("",int),batarg("months",int),batarg("s",oid))),
    1885             :  command("mtime", "day", MTIMEsql_day, false, "", args(1,2, arg("",lng),arg("msecs",lng))),
    1886             :  pattern("batmtime", "day", MTIMEsql_day_bulk, false, "", args(1,2, batarg("",lng),batarg("msecs",lng))),
    1887             :  pattern("batmtime", "day", MTIMEsql_day_bulk, false, "", args(1,3, batarg("",lng),batarg("msecs",lng),batarg("s",oid))),
    1888             :  command("mtime", "hours", MTIMEsql_hours, false, "", args(1,2, arg("",int),arg("msecs",lng))),
    1889             :  pattern("batmtime", "hours", MTIMEsql_hours_bulk, false, "", args(1,2, batarg("",int),batarg("msecs",lng))),
    1890             :  pattern("batmtime", "hours", MTIMEsql_hours_bulk, false, "", args(1,3, batarg("",int),batarg("msecs",lng),batarg("s",oid))),
    1891             :  command("mtime", "minutes", MTIMEsql_minutes, false, "", args(1,2, arg("",int),arg("msecs",lng))),
    1892             :  pattern("batmtime", "minutes", MTIMEsql_minutes_bulk, false, "", args(1,2, batarg("",int),batarg("msecs",lng))),
    1893             :  pattern("batmtime", "minutes", MTIMEsql_minutes_bulk, false, "", args(1,3, batarg("",int),batarg("msecs",lng),batarg("s",oid))),
    1894             :  command("mtime", "seconds", MTIMEsql_seconds, false, "", args(1,2, arg("",int),arg("msecs",lng))),
    1895             :  pattern("batmtime", "seconds", MTIMEsql_seconds_bulk, false, "", args(1,2, batarg("",int),batarg("msecs",lng))),
    1896             :  pattern("batmtime", "seconds", MTIMEsql_seconds_bulk, false, "", args(1,3, batarg("",int),batarg("msecs",lng),batarg("s",oid))),
    1897             :  command("mtime", "epoch_ms", MTIMEmsec_extract_epoch_ms, false, "", args(1,2, arg("",lng),arg("msecs",lng))),
    1898             :  pattern("batmtime", "epoch_ms", MTIMEmsec_extract_epoch_ms_bulk, false, "", args(1,2, batarg("",lng),batarg("msecs",lng))),
    1899             :  pattern("batmtime", "epoch_ms", MTIMEmsec_extract_epoch_ms_bulk, false, "", args(1,3, batarg("",lng),batarg("msecs",lng),batarg("s",oid))),
    1900             :  command("calc", "date", MTIMEdate_fromstr, false, "", args(1,2, arg("",date),arg("s",str))),
    1901             :  command("calc", "date", MTIMEdate_date, false, "", args(1,2, arg("",date),arg("d",date))),
    1902             :  command("calc", "date", MTIMEtimestamp_extract_date, false, "", args(1,2, arg("",date),arg("t",timestamp))),
    1903             :  command("calc", "datetz", MTIMEtimestamp_tz_extract_date, false, "", args(1,3, arg("",date),arg("t",timestamp),arg("tz_msec",lng))),
    1904             :  command("calc", "timestamp", MTIMEtimestamp_fromstr, false, "", args(1,2, arg("",timestamp),arg("s",str))),
    1905             :  command("calc", "timestamp", MTIMEtimestamp_timestamp, false, "", args(1,2, arg("",timestamp),arg("t",timestamp))),
    1906             :  command("calc", "timestamp", MTIMEtimestamp_fromdate, false, "", args(1,2, arg("",timestamp),arg("d",date))),
    1907             :  command("calc", "timestamp", MTIMEtimestamp_fromsecond, false, "", args(1,2, arg("",timestamp),arg("secs",int))),
    1908             :  command("calc", "timestamp", MTIMEtimestamp_frommsec, false, "", args(1,2, arg("",timestamp),arg("msecs",lng))),
    1909             :  command("calc", "daytime", MTIMEdaytime_fromstr, false, "", args(1,2, arg("",daytime),arg("s",str))),
    1910             :  command("calc", "daytime", MTIMEdaytime_daytime, false, "", args(1,2, arg("",daytime),arg("d",daytime))),
    1911             :  command("calc", "daytime", MTIMEdaytime_fromseconds, false, "", args(1,2, arg("",daytime),arg("s",lng))),
    1912             :  command("calc", "daytime", MTIMEtimestamp_extract_daytime, false, "", args(1,2, arg("",daytime),arg("t",timestamp))),
    1913             : // pattern("batcalc", "date", MTIMEdate_fromstr_bulk, false, "", args(1,2, batarg("",date),batarg("s",str))),
    1914             :  pattern("batcalc", "date", MTIMEdate_fromstr_bulk, false, "", args(1,3, batarg("",date),batarg("s",str),batarg("s",oid))),
    1915             : // pattern("batcalc", "date", MTIMEdate_date_bulk, false, "", args(1,2, batarg("",date),batarg("d",date))),
    1916             :  pattern("batcalc", "date", MTIMEdate_date_bulk, false, "", args(1,3, batarg("",date),batarg("d",date),batarg("s",oid))),
    1917             : // pattern("batcalc", "date", MTIMEtimestamp_extract_date_bulk, false, "", args(1,2, batarg("",date),batarg("t",timestamp))),
    1918             :  pattern("batcalc", "date", MTIMEtimestamp_extract_date_bulk, false, "", args(1,3, batarg("",date),batarg("t",timestamp),batarg("s",oid))),
    1919             :  pattern("batcalc", "datetz", MTIMEtimestamp_tz_extract_date_bulk, false, "", args(1,3, batarg("",date),batarg("t",timestamp),batarg("tz_msec",lng))),
    1920             :  pattern("batcalc", "datetz", MTIMEtimestamp_tz_extract_date_bulk, false, "", args(1,5, batarg("",date),batarg("t",timestamp),batarg("tz_msec",lng),batarg("s1",oid),batarg("s2",oid))),
    1921             :  pattern("batcalc", "datetz", MTIMEtimestamp_tz_extract_date_bulk_p1, false, "", args(1,3, batarg("",date),arg("t",timestamp),batarg("tz_msec",lng))),
    1922             :  pattern("batcalc", "datetz", MTIMEtimestamp_tz_extract_date_bulk_p1, false, "", args(1,4, batarg("",date),arg("t",timestamp),batarg("tz_msec",lng),batarg("s",oid))),
    1923             :  pattern("batcalc", "datetz", MTIMEtimestamp_tz_extract_date_bulk_p2, false, "", args(1,3, batarg("",date),batarg("t",timestamp),arg("tz_msec",lng))),
    1924             :  pattern("batcalc", "datetz", MTIMEtimestamp_tz_extract_date_bulk_p2, false, "", args(1,4, batarg("",date),batarg("t",timestamp),arg("tz_msec",lng),batarg("s",oid))),
    1925             : // pattern("batcalc", "timestamp", MTIMEtimestamp_fromstr_bulk, false, "", args(1,2, batarg("",timestamp),batarg("s",str))),
    1926             :  pattern("batcalc", "timestamp", MTIMEtimestamp_fromstr_bulk, false, "", args(1,3, batarg("",timestamp),batarg("s",str),batarg("s",oid))),
    1927             : // pattern("batcalc", "timestamp", MTIMEtimestamp_timestamp_bulk, false, "", args(1,2, batarg("",timestamp),batarg("t",timestamp))),
    1928             :  pattern("batcalc", "timestamp", MTIMEtimestamp_timestamp_bulk, false, "", args(1,3, batarg("",timestamp),batarg("t",timestamp),batarg("s",oid))),
    1929             : // pattern("batcalc", "timestamp", MTIMEtimestamp_fromdate_bulk, false, "", args(1,2, batarg("",timestamp),batarg("d",date))),
    1930             :  pattern("batcalc", "timestamp", MTIMEtimestamp_fromdate_bulk, false, "", args(1,3, batarg("",timestamp),batarg("d",date),batarg("s",oid))),
    1931             : // pattern("batcalc", "timestamp", MTIMEtimestamp_fromsecond_bulk, false, "", args(1,2, batarg("",timestamp),batarg("secs",int))),
    1932             :  pattern("batcalc", "timestamp", MTIMEtimestamp_fromsecond_bulk, false, "", args(1,3, batarg("",timestamp),batarg("secs",int),batarg("s",oid))),
    1933             : // pattern("batcalc", "timestamp", MTIMEtimestamp_frommsec_bulk, false, "", args(1,2, batarg("",timestamp),batarg("msecs",lng))),
    1934             :  pattern("batcalc", "timestamp", MTIMEtimestamp_frommsec_bulk, false, "", args(1,3, batarg("",timestamp),batarg("msecs",lng),batarg("s",oid))),
    1935             : // pattern("batcalc", "daytime", MTIMEdaytime_fromstr_bulk, false, "", args(1,2, batarg("",daytime),batarg("s",str))),
    1936             :  pattern("batcalc", "daytime", MTIMEdaytime_fromstr_bulk, false, "", args(1,3, batarg("",daytime),batarg("s",str),batarg("s",oid))),
    1937             : // pattern("batcalc", "daytime", MTIMEdaytime_daytime_bulk, false, "", args(1,2, batarg("",daytime),batarg("d",daytime))),
    1938             :  pattern("batcalc", "daytime", MTIMEdaytime_daytime_bulk, false, "", args(1,3, batarg("",daytime),batarg("d",daytime),batarg("s",oid))),
    1939             : // pattern("batcalc", "daytime", MTIMEdaytime_fromseconds_bulk, false, "", args(1,2, batarg("",daytime),batarg("s",lng))),
    1940             :  pattern("batcalc", "daytime", MTIMEdaytime_fromseconds_bulk, false, "", args(1,3, batarg("",daytime),batarg("s",lng),batarg("s",oid))),
    1941             : // pattern("batcalc", "daytime", MTIMEtimestamp_extract_daytime_bulk, false, "", args(1,2, batarg("",daytime),batarg("t",timestamp))),
    1942             :  pattern("batcalc", "daytime", MTIMEtimestamp_extract_daytime_bulk, false, "", args(1,3, batarg("",daytime),batarg("t",timestamp),batarg("s",oid))),
    1943             :  // -- odbc timestampdiff variants
    1944             :  command("mtime", "timestampdiff_sec", MTIMEtimestampdiff_sec, false, "diff in seconds between 'val1' and 'val2'.", args(1,3, arg("",lng),arg("val1",timestamp),arg("val2",timestamp))),
    1945             :  pattern("batmtime", "timestampdiff_sec", MTIMEtimestampdiff_sec_bulk, false, "", args(1,3, batarg("",lng),batarg("val1",timestamp),batarg("val2",timestamp))),
    1946             :  pattern("batmtime", "timestampdiff_sec", MTIMEtimestampdiff_sec_bulk_p1, false, "", args(1,3, batarg("",lng),arg("val1",timestamp),batarg("val2",timestamp))),
    1947             :  pattern("batmtime", "timestampdiff_sec", MTIMEtimestampdiff_sec_bulk_p2, false, "", args(1,3, batarg("",lng),batarg("val1",timestamp),arg("val2",timestamp))),
    1948             :  pattern("batmtime", "timestampdiff_sec", MTIMEtimestampdiff_sec_bulk, false, "", args(1,5, batarg("",lng),batarg("val1",timestamp),batarg("val2",timestamp),batarg("s1",oid),batarg("s2",oid))),
    1949             :  pattern("batmtime", "timestampdiff_sec", MTIMEtimestampdiff_sec_bulk_p1, false, "", args(1,4, batarg("",lng),arg("val1",timestamp),batarg("val2",timestamp),batarg("s",oid))),
    1950             :  pattern("batmtime", "timestampdiff_sec", MTIMEtimestampdiff_sec_bulk_p2, false, "", args(1,4, batarg("",lng),batarg("val1",timestamp),arg("val2",timestamp),batarg("s",oid))),
    1951             :  // --
    1952             :  command("mtime", "timestampdiff_sec", MTIMEtimestampdiff_sec_d_ts, false, "diff in seconds between 'val1' and 'val2'.", args(1,3, arg("",lng),arg("val1",date),arg("val2",timestamp))),
    1953             :  pattern("batmtime", "timestampdiff_sec", MTIMEtimestampdiff_sec_d_ts_bulk, false, "", args(1,3, batarg("",lng),batarg("val1",date),batarg("val2",timestamp))),
    1954             :  pattern("batmtime", "timestampdiff_sec", MTIMEtimestampdiff_sec_d_ts_bulk_p1, false, "", args(1,3, batarg("",lng),arg("val1",date),batarg("val2",timestamp))),
    1955             :  pattern("batmtime", "timestampdiff_sec", MTIMEtimestampdiff_sec_d_ts_bulk_p2, false, "", args(1,3, batarg("",lng),batarg("val1",date),arg("val2",timestamp))),
    1956             :  pattern("batmtime", "timestampdiff_sec", MTIMEtimestampdiff_sec_d_ts_bulk, false, "", args(1,5, batarg("",lng),batarg("val1",date),batarg("val2",timestamp),batarg("s1",oid),batarg("s2",oid))),
    1957             :  pattern("batmtime", "timestampdiff_sec", MTIMEtimestampdiff_sec_d_ts_bulk_p1, false, "", args(1,4, batarg("",lng),arg("val1",date),batarg("val2",timestamp),batarg("s",oid))),
    1958             :  pattern("batmtime", "timestampdiff_sec", MTIMEtimestampdiff_sec_d_ts_bulk_p2, false, "", args(1,4, batarg("",lng),batarg("val1",date),arg("val2",timestamp),batarg("s",oid))),
    1959             :  // --
    1960             :  command("mtime", "timestampdiff_sec", MTIMEtimestampdiff_sec_ts_d, false, "diff in seconds between 'val1' and 'val2'.", args(1,3, arg("",lng),arg("val1",timestamp),arg("val2",date))),
    1961             :  pattern("batmtime", "timestampdiff_sec", MTIMEtimestampdiff_sec_ts_d_bulk, false, "", args(1,3, batarg("",lng),batarg("val1",timestamp),batarg("val2",date))),
    1962             :  pattern("batmtime", "timestampdiff_sec", MTIMEtimestampdiff_sec_ts_d_bulk_p1, false, "", args(1,3, batarg("",lng),arg("val1",timestamp),batarg("val2",date))),
    1963             :  pattern("batmtime", "timestampdiff_sec", MTIMEtimestampdiff_sec_ts_d_bulk_p2, false, "", args(1,3, batarg("",lng),batarg("val1",timestamp),arg("val2",date))),
    1964             :  pattern("batmtime", "timestampdiff_sec", MTIMEtimestampdiff_sec_ts_d_bulk, false, "", args(1,5, batarg("",lng),batarg("val1",timestamp),batarg("val2",date),batarg("s1",oid),batarg("s2",oid))),
    1965             :  pattern("batmtime", "timestampdiff_sec", MTIMEtimestampdiff_sec_ts_d_bulk_p1, false, "", args(1,4, batarg("",lng),arg("val1",timestamp),batarg("val2",date),batarg("s",oid))),
    1966             :  pattern("batmtime", "timestampdiff_sec", MTIMEtimestampdiff_sec_ts_d_bulk_p2, false, "", args(1,4, batarg("",lng),batarg("val1",timestamp),arg("val2",date),batarg("s",oid))),
    1967             :  // --
    1968             :  command("mtime", "timestampdiff_min", MTIMEtimestampdiff_min, false, "diff in min between 'val1' and 'val2'.", args(1,3, arg("",lng),arg("val1",timestamp),arg("val2",timestamp))),
    1969             :  pattern("batmtime", "timestampdiff_min", MTIMEtimestampdiff_min_bulk, false, "", args(1,3, batarg("",lng),batarg("val1",timestamp),batarg("val2",timestamp))),
    1970             :  pattern("batmtime", "timestampdiff_min", MTIMEtimestampdiff_min_bulk_p1, false, "", args(1,3, batarg("",lng),arg("val1",timestamp),batarg("val2",timestamp))),
    1971             :  pattern("batmtime", "timestampdiff_min", MTIMEtimestampdiff_min_bulk_p2, false, "", args(1,3, batarg("",lng),batarg("val1",timestamp),arg("val2",timestamp))),
    1972             :  pattern("batmtime", "timestampdiff_min", MTIMEtimestampdiff_min_bulk, false, "", args(1,5, batarg("",lng),batarg("val1",timestamp),batarg("val2",timestamp),batarg("s1",oid),batarg("s2",oid))),
    1973             :  pattern("batmtime", "timestampdiff_min", MTIMEtimestampdiff_min_bulk_p1, false, "", args(1,4, batarg("",lng),arg("val1",timestamp),batarg("val2",timestamp),batarg("s",oid))),
    1974             :  pattern("batmtime", "timestampdiff_min", MTIMEtimestampdiff_min_bulk_p2, false, "", args(1,4, batarg("",lng),batarg("val1",timestamp),arg("val2",timestamp),batarg("s",oid))),
    1975             :  // --
    1976             :  command("mtime", "timestampdiff_min", MTIMEtimestampdiff_min_d_ts, false, "diff in min between 'val1' and 'val2'.", args(1,3, arg("",lng),arg("val1",date),arg("val2",timestamp))),
    1977             :  pattern("batmtime", "timestampdiff_min", MTIMEtimestampdiff_min_d_ts_bulk, false, "", args(1,3, batarg("",lng),batarg("val1",date),batarg("val2",timestamp))),
    1978             :  pattern("batmtime", "timestampdiff_min", MTIMEtimestampdiff_min_d_ts_bulk_p1, false, "", args(1,3, batarg("",lng),arg("val1",date),batarg("val2",timestamp))),
    1979             :  pattern("batmtime", "timestampdiff_min", MTIMEtimestampdiff_min_d_ts_bulk_p2, false, "", args(1,3, batarg("",lng),batarg("val1",date),arg("val2",timestamp))),
    1980             :  pattern("batmtime", "timestampdiff_min", MTIMEtimestampdiff_min_d_ts_bulk, false, "", args(1,5, batarg("",lng),batarg("val1",date),batarg("val2",timestamp),batarg("s1",oid),batarg("s2",oid))),
    1981             :  pattern("batmtime", "timestampdiff_min", MTIMEtimestampdiff_min_d_ts_bulk_p1, false, "", args(1,4, batarg("",lng),arg("val1",date),batarg("val2",timestamp),batarg("s",oid))),
    1982             :  pattern("batmtime", "timestampdiff_min", MTIMEtimestampdiff_min_d_ts_bulk_p2, false, "", args(1,4, batarg("",lng),batarg("val1",date),arg("val2",timestamp),batarg("s",oid))),
    1983             :  // --
    1984             :  command("mtime", "timestampdiff_min", MTIMEtimestampdiff_min_ts_d, false, "diff in min between 'val1' and 'val2'.", args(1,3, arg("",lng),arg("val1",timestamp),arg("val2",date))),
    1985             :  pattern("batmtime", "timestampdiff_min", MTIMEtimestampdiff_min_ts_d_bulk, false, "", args(1,3, batarg("",lng),batarg("val1",timestamp),batarg("val2",date))),
    1986             :  pattern("batmtime", "timestampdiff_min", MTIMEtimestampdiff_min_ts_d_bulk_p1, false, "", args(1,3, batarg("",lng),arg("val1",timestamp),batarg("val2",date))),
    1987             :  pattern("batmtime", "timestampdiff_min", MTIMEtimestampdiff_min_ts_d_bulk_p2, false, "", args(1,3, batarg("",lng),batarg("val1",timestamp),arg("val2",date))),
    1988             :  pattern("batmtime", "timestampdiff_min", MTIMEtimestampdiff_min_ts_d_bulk, false, "", args(1,5, batarg("",lng),batarg("val1",timestamp),batarg("val2",date),batarg("s1",oid),batarg("s2",oid))),
    1989             :  pattern("batmtime", "timestampdiff_min", MTIMEtimestampdiff_min_ts_d_bulk_p1, false, "", args(1,4, batarg("",lng),arg("val1",timestamp),batarg("val2",date),batarg("s",oid))),
    1990             :  pattern("batmtime", "timestampdiff_min", MTIMEtimestampdiff_min_ts_d_bulk_p2, false, "", args(1,4, batarg("",lng),batarg("val1",timestamp),arg("val2",date),batarg("s",oid))),
    1991             :  // --
    1992             :  command("mtime", "timestampdiff_hour", MTIMEtimestampdiff_hour, false, "diff in hours between 'val1' and 'val2'.", args(1,3, arg("",lng),arg("val1",timestamp),arg("val2",timestamp))),
    1993             :  pattern("batmtime", "timestampdiff_hour", MTIMEtimestampdiff_hour_bulk, false, "", args(1,3, batarg("",lng),batarg("val1",timestamp),batarg("val2",timestamp))),
    1994             :  pattern("batmtime", "timestampdiff_hour", MTIMEtimestampdiff_hour_bulk_p1, false, "", args(1,3, batarg("",lng),arg("val1",timestamp),batarg("val2",timestamp))),
    1995             :  pattern("batmtime", "timestampdiff_hour", MTIMEtimestampdiff_hour_bulk_p2, false, "", args(1,3, batarg("",lng),batarg("val1",timestamp),arg("val2",timestamp))),
    1996             :  pattern("batmtime", "timestampdiff_hour", MTIMEtimestampdiff_hour_bulk, false, "", args(1,5, batarg("",lng),batarg("val1",timestamp),batarg("val2",timestamp),batarg("s1",oid),batarg("s2",oid))),
    1997             :  pattern("batmtime", "timestampdiff_hour", MTIMEtimestampdiff_hour_bulk_p1, false, "", args(1,4, batarg("",lng),arg("val1",timestamp),batarg("val2",timestamp),batarg("s",oid))),
    1998             :  pattern("batmtime", "timestampdiff_hour", MTIMEtimestampdiff_hour_bulk_p2, false, "", args(1,4, batarg("",lng),batarg("val1",timestamp),arg("val2",timestamp),batarg("s",oid))),
    1999             :  // --
    2000             :  command("mtime", "timestampdiff_hour", MTIMEtimestampdiff_hour_d_ts, false, "diff in hours between 'val1' and 'val2'.", args(1,3, arg("",lng),arg("val1",date),arg("val2",timestamp))),
    2001             :  pattern("batmtime", "timestampdiff_hour", MTIMEtimestampdiff_hour_d_ts_bulk, false, "", args(1,3, batarg("",lng),batarg("val1",date),batarg("val2",timestamp))),
    2002             :  pattern("batmtime", "timestampdiff_hour", MTIMEtimestampdiff_hour_d_ts_bulk_p1, false, "", args(1,3, batarg("",lng),arg("val1",date),batarg("val2",timestamp))),
    2003             :  pattern("batmtime", "timestampdiff_hour", MTIMEtimestampdiff_hour_d_ts_bulk_p2, false, "", args(1,3, batarg("",lng),batarg("val1",date),arg("val2",timestamp))),
    2004             :  pattern("batmtime", "timestampdiff_hour", MTIMEtimestampdiff_hour_d_ts_bulk, false, "", args(1,5, batarg("",lng),batarg("val1",date),batarg("val2",timestamp),batarg("s1",oid),batarg("s2",oid))),
    2005             :  pattern("batmtime", "timestampdiff_hour", MTIMEtimestampdiff_hour_d_ts_bulk_p1, false, "", args(1,4, batarg("",lng),arg("val1",date),batarg("val2",timestamp),batarg("s",oid))),
    2006             :  pattern("batmtime", "timestampdiff_hour", MTIMEtimestampdiff_hour_d_ts_bulk_p2, false, "", args(1,4, batarg("",lng),batarg("val1",date),arg("val2",timestamp),batarg("s",oid))),
    2007             :  // --
    2008             :  command("mtime", "timestampdiff_hour", MTIMEtimestampdiff_hour_ts_d, false, "diff in hours between 'val1' and 'val2'.", args(1,3, arg("",lng),arg("val1",timestamp),arg("val2",date))),
    2009             :  pattern("batmtime", "timestampdiff_hour", MTIMEtimestampdiff_hour_ts_d_bulk, false, "", args(1,3, batarg("",lng),batarg("val1",timestamp),batarg("val2",date))),
    2010             :  pattern("batmtime", "timestampdiff_hour", MTIMEtimestampdiff_hour_ts_d_bulk_p1, false, "", args(1,3, batarg("",lng),arg("val1",timestamp),batarg("val2",date))),
    2011             :  pattern("batmtime", "timestampdiff_hour", MTIMEtimestampdiff_hour_ts_d_bulk_p2, false, "", args(1,3, batarg("",lng),batarg("val1",timestamp),arg("val2",date))),
    2012             :  pattern("batmtime", "timestampdiff_hour", MTIMEtimestampdiff_hour_ts_d_bulk, false, "", args(1,5, batarg("",lng),batarg("val1",timestamp),batarg("val2",date),batarg("s1",oid),batarg("s2",oid))),
    2013             :  pattern("batmtime", "timestampdiff_hour", MTIMEtimestampdiff_hour_ts_d_bulk_p1, false, "", args(1,4, batarg("",lng),arg("val1",timestamp),batarg("val2",date),batarg("s",oid))),
    2014             :  pattern("batmtime", "timestampdiff_hour", MTIMEtimestampdiff_hour_ts_d_bulk_p2, false, "", args(1,4, batarg("",lng),batarg("val1",timestamp),arg("val2",date),batarg("s",oid))),
    2015             :  // --
    2016             :  command("mtime", "timestampdiff_day", MTIMEtimestampdiff_day, false, "diff in days between 'val1' and 'val2'.", args(1,3, arg("",int),arg("val1",timestamp),arg("val2",timestamp))),
    2017             :  pattern("batmtime", "timestampdiff_day", MTIMEtimestampdiff_day_bulk, false, "", args(1,3, batarg("",int),batarg("val1",timestamp),batarg("val2",timestamp))),
    2018             :  pattern("batmtime", "timestampdiff_day", MTIMEtimestampdiff_day_bulk_p1, false, "", args(1,3, batarg("",int),arg("val1",timestamp),batarg("val2",timestamp))),
    2019             :  pattern("batmtime", "timestampdiff_day", MTIMEtimestampdiff_day_bulk_p2, false, "", args(1,3, batarg("",int),batarg("val1",timestamp),arg("val2",timestamp))),
    2020             :  pattern("batmtime", "timestampdiff_day", MTIMEtimestampdiff_day_bulk, false, "", args(1,5, batarg("",int),batarg("val1",timestamp),batarg("val2",timestamp),batarg("s1",oid),batarg("s2",oid))),
    2021             :  pattern("batmtime", "timestampdiff_day", MTIMEtimestampdiff_day_bulk_p1, false, "", args(1,4, batarg("",int),arg("val1",timestamp),batarg("val2",timestamp),batarg("s",oid))),
    2022             :  pattern("batmtime", "timestampdiff_day", MTIMEtimestampdiff_day_bulk_p2, false, "", args(1,4, batarg("",int),batarg("val1",timestamp),arg("val2",timestamp),batarg("s",oid))),
    2023             :  // --
    2024             :  command("mtime", "timestampdiff_day", MTIMEtimestampdiff_day_t_ts, false, "diff in days between 'val1' and 'val2'.", args(1,3, arg("",int),arg("val1",daytime),arg("val2",timestamp))),
    2025             :  pattern("batmtime", "timestampdiff_day", MTIMEtimestampdiff_day_t_ts_bulk, false, "", args(1,3, batarg("",int),batarg("val1",daytime),batarg("val2",timestamp))),
    2026             :  pattern("batmtime", "timestampdiff_day", MTIMEtimestampdiff_day_t_ts_bulk_p1, false, "", args(1,3, batarg("",int),arg("val1",daytime),batarg("val2",timestamp))),
    2027             :  pattern("batmtime", "timestampdiff_day", MTIMEtimestampdiff_day_t_ts_bulk_p2, false, "", args(1,3, batarg("",int),batarg("val1",daytime),arg("val2",timestamp))),
    2028             :  pattern("batmtime", "timestampdiff_day", MTIMEtimestampdiff_day_t_ts_bulk, false, "", args(1,5, batarg("",int),batarg("val1",daytime),batarg("val2",timestamp),batarg("s1",oid),batarg("s2",oid))),
    2029             :  pattern("batmtime", "timestampdiff_day", MTIMEtimestampdiff_day_t_ts_bulk_p1, false, "", args(1,4, batarg("",int),arg("val1",daytime),batarg("val2",timestamp),batarg("s",oid))),
    2030             :  pattern("batmtime", "timestampdiff_day", MTIMEtimestampdiff_day_t_ts_bulk_p2, false, "", args(1,4, batarg("",int),batarg("val1",daytime),arg("val2",timestamp),batarg("s",oid))),
    2031             :  // --
    2032             :  command("mtime", "timestampdiff_day", MTIMEtimestampdiff_day_ts_t, false, "diff in days between 'val1' and 'val2'.", args(1,3, arg("",int),arg("val1",timestamp),arg("val2",daytime))),
    2033             :  pattern("batmtime", "timestampdiff_day", MTIMEtimestampdiff_day_ts_t_bulk, false, "", args(1,3, batarg("",int),batarg("val1",timestamp),batarg("val2",daytime))),
    2034             :  pattern("batmtime", "timestampdiff_day", MTIMEtimestampdiff_day_ts_t_bulk_p1, false, "", args(1,3, batarg("",int),arg("val1",timestamp),batarg("val2",daytime))),
    2035             :  pattern("batmtime", "timestampdiff_day", MTIMEtimestampdiff_day_ts_t_bulk_p2, false, "", args(1,3, batarg("",int),batarg("val1",timestamp),arg("val2",daytime))),
    2036             :  pattern("batmtime", "timestampdiff_day", MTIMEtimestampdiff_day_ts_t_bulk, false, "", args(1,5, batarg("",int),batarg("val1",timestamp),batarg("val2",daytime),batarg("s1",oid),batarg("s2",oid))),
    2037             :  pattern("batmtime", "timestampdiff_day", MTIMEtimestampdiff_day_ts_t_bulk_p1, false, "", args(1,4, batarg("",int),arg("val1",timestamp),batarg("val2",daytime),batarg("s",oid))),
    2038             :  pattern("batmtime", "timestampdiff_day", MTIMEtimestampdiff_day_ts_t_bulk_p2, false, "", args(1,4, batarg("",int),batarg("val1",timestamp),arg("val2",daytime),batarg("s",oid))),
    2039             :  // --
    2040             :  command("mtime", "timestampdiff_week", MTIMEtimestampdiff_week, false, "diff in weeks between 'val1' and 'val2'.", args(1,3, arg("",int),arg("val1",timestamp),arg("val2",timestamp))),
    2041             :  pattern("batmtime", "timestampdiff_week", MTIMEtimestampdiff_week_bulk, false, "", args(1,3, batarg("",int),batarg("val1",timestamp),batarg("val2",timestamp))),
    2042             :  pattern("batmtime", "timestampdiff_week", MTIMEtimestampdiff_week_bulk_p1, false, "", args(1,3, batarg("",int),arg("val1",timestamp),batarg("val2",timestamp))),
    2043             :  pattern("batmtime", "timestampdiff_week", MTIMEtimestampdiff_week_bulk_p2, false, "", args(1,3, batarg("",int),batarg("val1",timestamp),arg("val2",timestamp))),
    2044             :  pattern("batmtime", "timestampdiff_week", MTIMEtimestampdiff_week_bulk, false, "", args(1,5, batarg("",int),batarg("val1",timestamp),batarg("val2",timestamp),batarg("s1",oid),batarg("s2",oid))),
    2045             :  pattern("batmtime", "timestampdiff_week", MTIMEtimestampdiff_week_bulk_p1, false, "", args(1,4, batarg("",int),arg("val1",timestamp),batarg("val2",timestamp),batarg("s",oid))),
    2046             :  pattern("batmtime", "timestampdiff_week", MTIMEtimestampdiff_week_bulk_p2, false, "", args(1,4, batarg("",int),batarg("val1",timestamp),arg("val2",timestamp),batarg("s",oid))),
    2047             :  // --
    2048             :  command("mtime", "timestampdiff_week", MTIMEtimestampdiff_week_t_ts, false, "diff in weeks between 'val1' and 'val2'.", args(1,3, arg("",int),arg("val1",daytime),arg("val2",timestamp))),
    2049             :  pattern("batmtime", "timestampdiff_week", MTIMEtimestampdiff_week_t_ts_bulk, false, "", args(1,3, batarg("",int),batarg("val1",daytime),batarg("val2",timestamp))),
    2050             :  pattern("batmtime", "timestampdiff_week", MTIMEtimestampdiff_week_t_ts_bulk_p1, false, "", args(1,3, batarg("",int),arg("val1",daytime),batarg("val2",timestamp))),
    2051             :  pattern("batmtime", "timestampdiff_week", MTIMEtimestampdiff_week_t_ts_bulk_p2, false, "", args(1,3, batarg("",int),batarg("val1",daytime),arg("val2",timestamp))),
    2052             :  pattern("batmtime", "timestampdiff_week", MTIMEtimestampdiff_week_t_ts_bulk, false, "", args(1,5, batarg("",int),batarg("val1",daytime),batarg("val2",timestamp),batarg("s1",oid),batarg("s2",oid))),
    2053             :  pattern("batmtime", "timestampdiff_week", MTIMEtimestampdiff_week_t_ts_bulk_p1, false, "", args(1,4, batarg("",int),arg("val1",daytime),batarg("val2",timestamp),batarg("s",oid))),
    2054             :  pattern("batmtime", "timestampdiff_week", MTIMEtimestampdiff_week_t_ts_bulk_p2, false, "", args(1,4, batarg("",int),batarg("val1",daytime),arg("val2",timestamp),batarg("s",oid))),
    2055             :  // --
    2056             :  command("mtime", "timestampdiff_week", MTIMEtimestampdiff_week_ts_t, false, "diff in weeks between 'val1' and 'val2'.", args(1,3, arg("",int),arg("val1",timestamp),arg("val2",daytime))),
    2057             :  pattern("batmtime", "timestampdiff_week", MTIMEtimestampdiff_week_ts_t_bulk, false, "", args(1,3, batarg("",int),batarg("val1",timestamp),batarg("val2",daytime))),
    2058             :  pattern("batmtime", "timestampdiff_week", MTIMEtimestampdiff_week_ts_t_bulk_p1, false, "", args(1,3, batarg("",int),arg("val1",timestamp),batarg("val2",daytime))),
    2059             :  pattern("batmtime", "timestampdiff_week", MTIMEtimestampdiff_week_ts_t_bulk_p2, false, "", args(1,3, batarg("",int),batarg("val1",timestamp),arg("val2",daytime))),
    2060             :  pattern("batmtime", "timestampdiff_week", MTIMEtimestampdiff_week_ts_t_bulk, false, "", args(1,5, batarg("",int),batarg("val1",timestamp),batarg("val2",daytime),batarg("s1",oid),batarg("s2",oid))),
    2061             :  pattern("batmtime", "timestampdiff_week", MTIMEtimestampdiff_week_ts_t_bulk_p1, false, "", args(1,4, batarg("",int),arg("val1",timestamp),batarg("val2",daytime),batarg("s",oid))),
    2062             :  pattern("batmtime", "timestampdiff_week", MTIMEtimestampdiff_week_ts_t_bulk_p2, false, "", args(1,4, batarg("",int),batarg("val1",timestamp),arg("val2",daytime),batarg("s",oid))),
    2063             :  // --
    2064             :  command("mtime", "timestampdiff_month", MTIMEtimestampdiff_month, false, "diff in months between 'val1' and 'val2'.", args(1,3, arg("",int),arg("val1",timestamp),arg("val2",timestamp))),
    2065             :  pattern("batmtime", "timestampdiff_month", MTIMEtimestampdiff_month_bulk, false, "", args(1,3, batarg("",int),batarg("val1",timestamp),batarg("val2",timestamp))),
    2066             :  pattern("batmtime", "timestampdiff_month", MTIMEtimestampdiff_month_bulk_p1, false, "", args(1,3, batarg("",int),arg("val1",timestamp),batarg("val2",timestamp))),
    2067             :  pattern("batmtime", "timestampdiff_month", MTIMEtimestampdiff_month_bulk_p2, false, "", args(1,3, batarg("",int),batarg("val1",timestamp),arg("val2",timestamp))),
    2068             :  pattern("batmtime", "timestampdiff_month", MTIMEtimestampdiff_month_bulk, false, "", args(1,5, batarg("",int),batarg("val1",timestamp),batarg("val2",timestamp),batarg("s1",oid),batarg("s2",oid))),
    2069             :  pattern("batmtime", "timestampdiff_month", MTIMEtimestampdiff_month_bulk_p1, false, "", args(1,4, batarg("",int),arg("val1",timestamp),batarg("val2",timestamp),batarg("s",oid))),
    2070             :  pattern("batmtime", "timestampdiff_month", MTIMEtimestampdiff_month_bulk_p2, false, "", args(1,4, batarg("",int),batarg("val1",timestamp),arg("val2",timestamp),batarg("s",oid))),
    2071             :  // --
    2072             :  command("mtime", "timestampdiff_month", MTIMEtimestampdiff_month_t_ts, false, "diff in months between 'val1' and 'val2'.", args(1,3, arg("",int),arg("val1",daytime),arg("val2",timestamp))),
    2073             :  pattern("batmtime", "timestampdiff_month", MTIMEtimestampdiff_month_t_ts_bulk, false, "", args(1,3, batarg("",int),batarg("val1",daytime),batarg("val2",timestamp))),
    2074             :  pattern("batmtime", "timestampdiff_month", MTIMEtimestampdiff_month_t_ts_bulk_p1, false, "", args(1,3, batarg("",int),arg("val1",daytime),batarg("val2",timestamp))),
    2075             :  pattern("batmtime", "timestampdiff_month", MTIMEtimestampdiff_month_t_ts_bulk_p2, false, "", args(1,3, batarg("",int),batarg("val1",daytime),arg("val2",timestamp))),
    2076             :  pattern("batmtime", "timestampdiff_month", MTIMEtimestampdiff_month_t_ts_bulk, false, "", args(1,5, batarg("",int),batarg("val1",daytime),batarg("val2",timestamp),batarg("s1",oid),batarg("s2",oid))),
    2077             :  pattern("batmtime", "timestampdiff_month", MTIMEtimestampdiff_month_t_ts_bulk_p1, false, "", args(1,4, batarg("",int),arg("val1",daytime),batarg("val2",timestamp),batarg("s",oid))),
    2078             :  pattern("batmtime", "timestampdiff_month", MTIMEtimestampdiff_month_t_ts_bulk_p2, false, "", args(1,4, batarg("",int),batarg("val1",daytime),arg("val2",timestamp),batarg("s",oid))),
    2079             :  // --
    2080             :  command("mtime", "timestampdiff_month", MTIMEtimestampdiff_month_ts_t, false, "diff in months between 'val1' and 'val2'.", args(1,3, arg("",int),arg("val1",timestamp),arg("val2",daytime))),
    2081             :  pattern("batmtime", "timestampdiff_month", MTIMEtimestampdiff_month_ts_t_bulk, false, "", args(1,3, batarg("",int),batarg("val1",timestamp),batarg("val2",daytime))),
    2082             :  pattern("batmtime", "timestampdiff_month", MTIMEtimestampdiff_month_ts_t_bulk_p1, false, "", args(1,3, batarg("",int),arg("val1",timestamp),batarg("val2",daytime))),
    2083             :  pattern("batmtime", "timestampdiff_month", MTIMEtimestampdiff_month_ts_t_bulk_p2, false, "", args(1,3, batarg("",int),batarg("val1",timestamp),arg("val2",daytime))),
    2084             :  pattern("batmtime", "timestampdiff_month", MTIMEtimestampdiff_month_ts_t_bulk, false, "", args(1,5, batarg("",int),batarg("val1",timestamp),batarg("val2",daytime),batarg("s1",oid),batarg("s2",oid))),
    2085             :  pattern("batmtime", "timestampdiff_month", MTIMEtimestampdiff_month_ts_t_bulk_p1, false, "", args(1,4, batarg("",int),arg("val1",timestamp),batarg("val2",daytime),batarg("s",oid))),
    2086             :  pattern("batmtime", "timestampdiff_month", MTIMEtimestampdiff_month_ts_t_bulk_p2, false, "", args(1,4, batarg("",int),batarg("val1",timestamp),arg("val2",daytime),batarg("s",oid))),
    2087             :  // --
    2088             :  command("mtime", "timestampdiff_quarter", MTIMEtimestampdiff_quarter, false, "diff in months between 'val1' and 'val2'.", args(1,3, arg("",int),arg("val1",timestamp),arg("val2",timestamp))),
    2089             :  pattern("batmtime", "timestampdiff_quarter", MTIMEtimestampdiff_quarter_bulk, false, "", args(1,3, batarg("",int),batarg("val1",timestamp),batarg("val2",timestamp))),
    2090             :  pattern("batmtime", "timestampdiff_quarter", MTIMEtimestampdiff_quarter_bulk_p1, false, "", args(1,3, batarg("",int),arg("val1",timestamp),batarg("val2",timestamp))),
    2091             :  pattern("batmtime", "timestampdiff_quarter", MTIMEtimestampdiff_quarter_bulk_p2, false, "", args(1,3, batarg("",int),batarg("val1",timestamp),arg("val2",timestamp))),
    2092             :  pattern("batmtime", "timestampdiff_quarter", MTIMEtimestampdiff_quarter_bulk, false, "", args(1,5, batarg("",int),batarg("val1",timestamp),batarg("val2",timestamp),batarg("s1",oid),batarg("s2",oid))),
    2093             :  pattern("batmtime", "timestampdiff_quarter", MTIMEtimestampdiff_quarter_bulk_p1, false, "", args(1,4, batarg("",int),arg("val1",timestamp),batarg("val2",timestamp),batarg("s",oid))),
    2094             :  pattern("batmtime", "timestampdiff_quarter", MTIMEtimestampdiff_quarter_bulk_p2, false, "", args(1,4, batarg("",int),batarg("val1",timestamp),arg("val2",timestamp),batarg("s",oid))),
    2095             :  // --
    2096             :  command("mtime", "timestampdiff_quarter", MTIMEtimestampdiff_quarter_t_ts, false, "diff in months between 'val1' and 'val2'.", args(1,3, arg("",int),arg("val1",daytime),arg("val2",timestamp))),
    2097             :  pattern("batmtime", "timestampdiff_quarter", MTIMEtimestampdiff_quarter_t_ts_bulk, false, "", args(1,3, batarg("",int),batarg("val1",daytime),batarg("val2",timestamp))),
    2098             :  pattern("batmtime", "timestampdiff_quarter", MTIMEtimestampdiff_quarter_t_ts_bulk_p1, false, "", args(1,3, batarg("",int),arg("val1",daytime),batarg("val2",timestamp))),
    2099             :  pattern("batmtime", "timestampdiff_quarter", MTIMEtimestampdiff_quarter_t_ts_bulk_p2, false, "", args(1,3, batarg("",int),batarg("val1",daytime),arg("val2",timestamp))),
    2100             :  pattern("batmtime", "timestampdiff_quarter", MTIMEtimestampdiff_quarter_t_ts_bulk, false, "", args(1,5, batarg("",int),batarg("val1",daytime),batarg("val2",timestamp),batarg("s1",oid),batarg("s2",oid))),
    2101             :  pattern("batmtime", "timestampdiff_quarter", MTIMEtimestampdiff_quarter_t_ts_bulk_p1, false, "", args(1,4, batarg("",int),arg("val1",daytime),batarg("val2",timestamp),batarg("s",oid))),
    2102             :  pattern("batmtime", "timestampdiff_quarter", MTIMEtimestampdiff_quarter_t_ts_bulk_p2, false, "", args(1,4, batarg("",int),batarg("val1",daytime),arg("val2",timestamp),batarg("s",oid))),
    2103             :  // --
    2104             :  command("mtime", "timestampdiff_quarter", MTIMEtimestampdiff_quarter_ts_t, false, "diff in months between 'val1' and 'val2'.", args(1,3, arg("",int),arg("val1",timestamp),arg("val2",daytime))),
    2105             :  pattern("batmtime", "timestampdiff_quarter", MTIMEtimestampdiff_quarter_ts_t_bulk, false, "", args(1,3, batarg("",int),batarg("val1",timestamp),batarg("val2",daytime))),
    2106             :  pattern("batmtime", "timestampdiff_quarter", MTIMEtimestampdiff_quarter_ts_t_bulk_p1, false, "", args(1,3, batarg("",int),arg("val1",timestamp),batarg("val2",daytime))),
    2107             :  pattern("batmtime", "timestampdiff_quarter", MTIMEtimestampdiff_quarter_ts_t_bulk_p2, false, "", args(1,3, batarg("",int),batarg("val1",timestamp),arg("val2",daytime))),
    2108             :  pattern("batmtime", "timestampdiff_quarter", MTIMEtimestampdiff_quarter_ts_t_bulk, false, "", args(1,5, batarg("",int),batarg("val1",timestamp),batarg("val2",daytime),batarg("s1",oid),batarg("s2",oid))),
    2109             :  pattern("batmtime", "timestampdiff_quarter", MTIMEtimestampdiff_quarter_ts_t_bulk_p1, false, "", args(1,4, batarg("",int),arg("val1",timestamp),batarg("val2",daytime),batarg("s",oid))),
    2110             :  pattern("batmtime", "timestampdiff_quarter", MTIMEtimestampdiff_quarter_ts_t_bulk_p2, false, "", args(1,4, batarg("",int),batarg("val1",timestamp),arg("val2",daytime),batarg("s",oid))),
    2111             :  // --
    2112             :  command("mtime", "timestampdiff_year", MTIMEtimestampdiff_year, false, "diff in months between 'val1' and 'val2'.", args(1,3, arg("",int),arg("val1",timestamp),arg("val2",timestamp))),
    2113             :  pattern("batmtime", "timestampdiff_year", MTIMEtimestampdiff_year_bulk, false, "", args(1,3, batarg("",int),batarg("val1",timestamp),batarg("val2",timestamp))),
    2114             :  pattern("batmtime", "timestampdiff_year", MTIMEtimestampdiff_year_bulk_p1, false, "", args(1,3, batarg("",int),arg("val1",timestamp),batarg("val2",timestamp))),
    2115             :  pattern("batmtime", "timestampdiff_year", MTIMEtimestampdiff_year_bulk_p2, false, "", args(1,3, batarg("",int),batarg("val1",timestamp),arg("val2",timestamp))),
    2116             :  pattern("batmtime", "timestampdiff_year", MTIMEtimestampdiff_year_bulk, false, "", args(1,5, batarg("",int),batarg("val1",timestamp),batarg("val2",timestamp),batarg("s1",oid),batarg("s2",oid))),
    2117             :  pattern("batmtime", "timestampdiff_year", MTIMEtimestampdiff_year_bulk_p1, false, "", args(1,4, batarg("",int),arg("val1",timestamp),batarg("val2",timestamp),batarg("s",oid))),
    2118             :  pattern("batmtime", "timestampdiff_year", MTIMEtimestampdiff_year_bulk_p2, false, "", args(1,4, batarg("",int),batarg("val1",timestamp),arg("val2",timestamp),batarg("s",oid))),
    2119             :  // --
    2120             :  command("mtime", "timestampdiff_year", MTIMEtimestampdiff_year_t_ts, false, "diff in months between 'val1' and 'val2'.", args(1,3, arg("",int),arg("val1",daytime),arg("val2",timestamp))),
    2121             :  pattern("batmtime", "timestampdiff_year", MTIMEtimestampdiff_year_t_ts_bulk, false, "", args(1,3, batarg("",int),batarg("val1",daytime),batarg("val2",timestamp))),
    2122             :  pattern("batmtime", "timestampdiff_year", MTIMEtimestampdiff_year_t_ts_bulk_p1, false, "", args(1,3, batarg("",int),arg("val1",daytime),batarg("val2",timestamp))),
    2123             :  pattern("batmtime", "timestampdiff_year", MTIMEtimestampdiff_year_t_ts_bulk_p2, false, "", args(1,3, batarg("",int),batarg("val1",daytime),arg("val2",timestamp))),
    2124             :  pattern("batmtime", "timestampdiff_year", MTIMEtimestampdiff_year_t_ts_bulk, false, "", args(1,5, batarg("",int),batarg("val1",daytime),batarg("val2",timestamp),batarg("s1",oid),batarg("s2",oid))),
    2125             :  pattern("batmtime", "timestampdiff_year", MTIMEtimestampdiff_year_t_ts_bulk_p1, false, "", args(1,4, batarg("",int),arg("val1",daytime),batarg("val2",timestamp),batarg("s",oid))),
    2126             :  pattern("batmtime", "timestampdiff_year", MTIMEtimestampdiff_year_t_ts_bulk_p2, false, "", args(1,4, batarg("",int),batarg("val1",daytime),arg("val2",timestamp),batarg("s",oid))),
    2127             :  // --
    2128             :  command("mtime", "timestampdiff_year", MTIMEtimestampdiff_year_ts_t, false, "diff in months between 'val1' and 'val2'.", args(1,3, arg("",int),arg("val1",timestamp),arg("val2",daytime))),
    2129             :  pattern("batmtime", "timestampdiff_year", MTIMEtimestampdiff_year_ts_t_bulk, false, "", args(1,3, batarg("",int),batarg("val1",timestamp),batarg("val2",daytime))),
    2130             :  pattern("batmtime", "timestampdiff_year", MTIMEtimestampdiff_year_ts_t_bulk_p1, false, "", args(1,3, batarg("",int),arg("val1",timestamp),batarg("val2",daytime))),
    2131             :  pattern("batmtime", "timestampdiff_year", MTIMEtimestampdiff_year_ts_t_bulk_p2, false, "", args(1,3, batarg("",int),batarg("val1",timestamp),arg("val2",daytime))),
    2132             :  pattern("batmtime", "timestampdiff_year", MTIMEtimestampdiff_year_ts_t_bulk, false, "", args(1,5, batarg("",int),batarg("val1",timestamp),batarg("val2",daytime),batarg("s1",oid),batarg("s2",oid))),
    2133             :  pattern("batmtime", "timestampdiff_year", MTIMEtimestampdiff_year_ts_t_bulk_p1, false, "", args(1,4, batarg("",int),arg("val1",timestamp),batarg("val2",daytime),batarg("s",oid))),
    2134             :  pattern("batmtime", "timestampdiff_year", MTIMEtimestampdiff_year_ts_t_bulk_p2, false, "", args(1,4, batarg("",int),batarg("val1",timestamp),arg("val2",daytime),batarg("s",oid))),
    2135             :  { .imp=NULL }
    2136             : };
    2137             : #include "mal_import.h"
    2138             : #ifdef _MSC_VER
    2139             : #undef read
    2140             : #pragma section(".CRT$XCU",read)
    2141             : #endif
    2142         334 : LIB_STARTUP_FUNC(init_mtime_mal)
    2143         334 : { mal_module("mtime", NULL, mtime_init_funcs); }

Generated by: LCOV version 1.14