Changeset: 556773d60cb3 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=556773d60cb3
Modified Files:
        clients/Tests/MAL-signatures.stable.out
        clients/Tests/MAL-signatures.stable.out.int128
        clients/Tests/exports.stable.out
        monetdb5/modules/atoms/mtime.c
        monetdb5/modules/atoms/mtime.mal
        sql/common/sql_types.c
        sql/server/sql_datetime.c
        sql/server/sql_datetime.h
        sql/server/sql_parser.y
        sql/server/sql_scan.c
        sql/test/Tests/systemfunctions.stable.out
        sql/test/Tests/systemfunctions.stable.out.int128
        sql/test/emptydb-upgrade-chain-hge/Tests/upgrade.stable.out.int128
        
sql/test/emptydb-upgrade-chain-hge/Tests/upgrade.stable.out.powerpc64.int128
        sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out
        sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out.32bit
        sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out.int128
        sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out.powerpc64
        sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out.powerpc64.int128
        sql/test/emptydb-upgrade-hge/Tests/upgrade.stable.out.int128
        sql/test/emptydb-upgrade/Tests/upgrade.stable.out
        sql/test/emptydb-upgrade/Tests/upgrade.stable.out.32bit
        sql/test/emptydb-upgrade/Tests/upgrade.stable.out.int128
        sql/test/emptydb/Tests/check.stable.out
        sql/test/emptydb/Tests/check.stable.out.32bit
        sql/test/emptydb/Tests/check.stable.out.int128
        sql/test/pg_regress/Tests/date.stable.err
        sql/test/pg_regress/Tests/date.stable.out
        sql/test/pg_regress/Tests/timestamp.stable.err
        sql/test/pg_regress/Tests/timestamp.stable.out
        sql/test/pg_regress/Tests/timestamptz.stable.err
        sql/test/pg_regress/Tests/timestamptz.stable.out
        sql/test/testdb-upgrade-chain-hge/Tests/upgrade.stable.out.int128
        sql/test/testdb-upgrade-chain/Tests/upgrade.stable.out
        sql/test/testdb-upgrade-chain/Tests/upgrade.stable.out.32bit
        sql/test/testdb-upgrade-chain/Tests/upgrade.stable.out.int128
        sql/test/testdb-upgrade-hge/Tests/upgrade.stable.out.int128
        sql/test/testdb-upgrade/Tests/upgrade.stable.out
        sql/test/testdb-upgrade/Tests/upgrade.stable.out.32bit
        sql/test/testdb-upgrade/Tests/upgrade.stable.out.int128
Branch: mtime
Log Message:

Implemented EXTRACT(CENTURY FROM x) and EXTRACT(DECADE FROM x).


diffs (truncated from 34223 to 300 lines):

diff --git a/clients/Tests/MAL-signatures.stable.out 
b/clients/Tests/MAL-signatures.stable.out
--- a/clients/Tests/MAL-signatures.stable.out
+++ b/clients/Tests/MAL-signatures.stable.out
@@ -8917,7 +8917,9 @@ stdout of test 'MAL-signatures` in direc
 [ "batmmath",  "tanh", "command batmmath.tanh(x:bat[:dbl], 
s:bat[:oid]):bat[:dbl] ",   "CMDscience_bat_dbl_tanh_cand;",        ""      ]
 [ "batmmath",  "tanh", "command batmmath.tanh(x:bat[:flt]):bat[:flt] ",        
"CMDscience_bat_flt_tanh;",     ""      ]
 [ "batmmath",  "tanh", "command batmmath.tanh(x:bat[:flt], 
s:bat[:oid]):bat[:flt] ",   "CMDscience_bat_flt_tanh_cand;",        ""      ]
+[ "batmtime",  "century",      "command 
batmtime.century(d:bat[:date]):bat[:int] ",    
"MTIMEdate_extract_century_bulk;",      ""      ]
 [ "batmtime",  "day",  "command batmtime.day(d:bat[:date]):bat[:int] ",        
"MTIMEdate_extract_day_bulk;",  ""      ]
+[ "batmtime",  "decade",       "command 
batmtime.decade(d:bat[:date]):bat[:int] ",     
"MTIMEdate_extract_decade_bulk;",       ""      ]
 [ "batmtime",  "diff", "command batmtime.diff(b1:bat[:date], 
b2:bat[:date]):bat[:int] ",       "MTIMEdate_diff_bulk;", "Difference of two 
sets of date."       ]
 [ "batmtime",  "diff", "command batmtime.diff(b1:bat[:timestamp], 
b2:bat[:timestamp]):bat[:lng] ",     "MTIMEtimestamp_diff_msec_bulk;",       
"Difference of two sets of timestamp."  ]
 [ "batmtime",  "hours",        "command 
batmtime.hours(d:bat[:daytime]):bat[:int] ",   
"MTIMEdaytime_extract_hours_bulk;",     ""      ]
@@ -11355,6 +11357,8 @@ stdout of test 'MAL-signatures` in direc
 [ "mmath",     "tanh", "command mmath.tanh(x:dbl):dbl ",       
"MATHunary_TANHdbl;",   "The tanh() function returns the hyperbolic tangent of 
x, which is \n\tdefined mathematically as sinh(x) / cosh(x)."    ]
 [ "mmath",     "tanh", "command mmath.tanh(x:flt):flt ",       
"MATHunary_TANHflt;",   ""      ]
 [ "mtime",     "addmonths",    "command mtime.addmonths(value:date, 
months:int):date ",        "MTIMEdate_addmonths;", "returns the date after a 
number of\n\tmonths (possibly negative)."     ]
+[ "mtime",     "century",      "command mtime.century(d:date):int ",   
"MTIMEdate_extract_century;",   "extracts century from date."   ]
+[ "mtime",     "century",      "command mtime.century(t:timestamp):int ",      
"MTIMEtimestamp_century;",      ""      ]
 [ "mtime",     "current_date", "command mtime.current_date():date ",   
"MTIMEcurrent_date;",   ""      ]
 [ "mtime",     "current_time", "command mtime.current_time():daytime ",        
"MTIMEcurrent_time;",   ""      ]
 [ "mtime",     "current_timestamp",    "command 
mtime.current_timestamp():timestamp ", "MTIMEcurrent_timestamp;",      ""      ]
@@ -11367,6 +11371,8 @@ stdout of test 'MAL-signatures` in direc
 [ "mtime",     "day",  "command mtime.day(t:timestamp):int ",  
"MTIMEtimestamp_day;",  ""      ]
 [ "mtime",     "dayofweek",    "command mtime.dayofweek(d:date):int ", 
"MTIMEdate_extract_dayofweek;", "Returns the current day of the week\n\twhere 
1=monday, .., 7=sunday"   ]
 [ "mtime",     "dayofyear",    "command mtime.dayofyear(d:date):int ", 
"MTIMEdate_extract_dayofyear;", "Returns N where d is the Nth day\n\tof the 
year (january 1 returns 1)" ]
+[ "mtime",     "decade",       "command mtime.decade(d:date):int ",    
"MTIMEdate_extract_decade;",    "extracts decade from date."    ]
+[ "mtime",     "decade",       "command mtime.decade(t:timestamp):int ",       
"MTIMEtimestamp_decade;",       ""      ]
 [ "mtime",     "diff", "command mtime.diff(val1:date, val2:date):int ",        
"MTIMEdate_diff;",      "returns the number of days\n\tbetween 'val1' and 
'val2'."      ]
 [ "mtime",     "diff", "command mtime.diff(val1:daytime, val2:daytime):lng ",  
"MTIMEdaytime_diff_msec;",      "returns the number of msec between 'val1' and 
'val2'." ]
 [ "mtime",     "diff", "command mtime.diff(val1:timestamp, val2:timestamp):lng 
",      "MTIMEtimestamp_diff_msec;",    "returns the number of 
milliseconds\n\tbetween 'val1' and 'val2'."      ]
@@ -11398,7 +11404,7 @@ stdout of test 'MAL-signatures` in direc
 [ "mtime",     "timestamp_sub_msec_interval",  "command 
mtime.timestamp_sub_msec_interval(t:timestamp, ms:lng):timestamp ",    
"MTIMEtimestamp_sub_msec_interval;",    ""      ]
 [ "mtime",     "timestamp_to_str",     "command 
mtime.timestamp_to_str(d:timestamp, format:str):str ", 
"MTIMEtimestamp_to_str;",       "create a string from the time, using the 
specified format (see man strftime)"  ]
 [ "mtime",     "weekofyear",   "command mtime.weekofyear(d:date):int ",        
"MTIMEdate_extract_weekofyear;",        "Returns the week number in the year."  
]
-[ "mtime",     "year", "command mtime.year(d:date):int ",      
"MTIMEdate_extract_year;",      "extracts year from date (nonzero\n\tvalue 
between -5867411 and +5867411)."     ]
+[ "mtime",     "year", "command mtime.year(d:date):int ",      
"MTIMEdate_extract_year;",      "extracts year from date."      ]
 [ "mtime",     "year", "command mtime.year(months:int):int ",  
"MTIMEsql_year;",       ""      ]
 [ "mtime",     "year", "command mtime.year(t:timestamp):int ", 
"MTIMEtimestamp_year;", ""      ]
 [ "netcdf",    "attach",       "pattern netcdf.attach(filename:str):void ",    
"NCDFattach;",  "Register a NetCDF file in the vault"   ]
diff --git a/clients/Tests/MAL-signatures.stable.out.int128 
b/clients/Tests/MAL-signatures.stable.out.int128
--- a/clients/Tests/MAL-signatures.stable.out.int128
+++ b/clients/Tests/MAL-signatures.stable.out.int128
@@ -12645,7 +12645,9 @@ stdout of test 'MAL-signatures` in direc
 [ "batmmath",  "tanh", "command batmmath.tanh(x:bat[:dbl], 
s:bat[:oid]):bat[:dbl] ",   "CMDscience_bat_dbl_tanh_cand;",        ""      ]
 [ "batmmath",  "tanh", "command batmmath.tanh(x:bat[:flt]):bat[:flt] ",        
"CMDscience_bat_flt_tanh;",     ""      ]
 [ "batmmath",  "tanh", "command batmmath.tanh(x:bat[:flt], 
s:bat[:oid]):bat[:flt] ",   "CMDscience_bat_flt_tanh_cand;",        ""      ]
+[ "batmtime",  "century",      "command 
batmtime.century(d:bat[:date]):bat[:int] ",    
"MTIMEdate_extract_century_bulk;",      ""      ]
 [ "batmtime",  "day",  "command batmtime.day(d:bat[:date]):bat[:int] ",        
"MTIMEdate_extract_day_bulk;",  ""      ]
+[ "batmtime",  "decade",       "command 
batmtime.decade(d:bat[:date]):bat[:int] ",     
"MTIMEdate_extract_decade_bulk;",       ""      ]
 [ "batmtime",  "diff", "command batmtime.diff(b1:bat[:date], 
b2:bat[:date]):bat[:int] ",       "MTIMEdate_diff_bulk;", "Difference of two 
sets of date."       ]
 [ "batmtime",  "diff", "command batmtime.diff(b1:bat[:timestamp], 
b2:bat[:timestamp]):bat[:lng] ",     "MTIMEtimestamp_diff_msec_bulk;",       
"Difference of two sets of timestamp."  ]
 [ "batmtime",  "hours",        "command 
batmtime.hours(d:bat[:daytime]):bat[:int] ",   
"MTIMEdaytime_extract_hours_bulk;",     ""      ]
@@ -15767,6 +15769,8 @@ stdout of test 'MAL-signatures` in direc
 [ "mmath",     "tanh", "command mmath.tanh(x:dbl):dbl ",       
"MATHunary_TANHdbl;",   "The tanh() function returns the hyperbolic tangent of 
x, which is \n\tdefined mathematically as sinh(x) / cosh(x)."    ]
 [ "mmath",     "tanh", "command mmath.tanh(x:flt):flt ",       
"MATHunary_TANHflt;",   ""      ]
 [ "mtime",     "addmonths",    "command mtime.addmonths(value:date, 
months:int):date ",        "MTIMEdate_addmonths;", "returns the date after a 
number of\n\tmonths (possibly negative)."     ]
+[ "mtime",     "century",      "command mtime.century(d:date):int ",   
"MTIMEdate_extract_century;",   "extracts century from date."   ]
+[ "mtime",     "century",      "command mtime.century(t:timestamp):int ",      
"MTIMEtimestamp_century;",      ""      ]
 [ "mtime",     "current_date", "command mtime.current_date():date ",   
"MTIMEcurrent_date;",   ""      ]
 [ "mtime",     "current_time", "command mtime.current_time():daytime ",        
"MTIMEcurrent_time;",   ""      ]
 [ "mtime",     "current_timestamp",    "command 
mtime.current_timestamp():timestamp ", "MTIMEcurrent_timestamp;",      ""      ]
@@ -15779,6 +15783,8 @@ stdout of test 'MAL-signatures` in direc
 [ "mtime",     "day",  "command mtime.day(t:timestamp):int ",  
"MTIMEtimestamp_day;",  ""      ]
 [ "mtime",     "dayofweek",    "command mtime.dayofweek(d:date):int ", 
"MTIMEdate_extract_dayofweek;", "Returns the current day of the week\n\twhere 
1=monday, .., 7=sunday"   ]
 [ "mtime",     "dayofyear",    "command mtime.dayofyear(d:date):int ", 
"MTIMEdate_extract_dayofyear;", "Returns N where d is the Nth day\n\tof the 
year (january 1 returns 1)" ]
+[ "mtime",     "decade",       "command mtime.decade(d:date):int ",    
"MTIMEdate_extract_decade;",    "extracts decade from date."    ]
+[ "mtime",     "decade",       "command mtime.decade(t:timestamp):int ",       
"MTIMEtimestamp_decade;",       ""      ]
 [ "mtime",     "diff", "command mtime.diff(val1:date, val2:date):int ",        
"MTIMEdate_diff;",      "returns the number of days\n\tbetween 'val1' and 
'val2'."      ]
 [ "mtime",     "diff", "command mtime.diff(val1:daytime, val2:daytime):lng ",  
"MTIMEdaytime_diff_msec;",      "returns the number of msec between 'val1' and 
'val2'." ]
 [ "mtime",     "diff", "command mtime.diff(val1:timestamp, val2:timestamp):lng 
",      "MTIMEtimestamp_diff_msec;",    "returns the number of 
milliseconds\n\tbetween 'val1' and 'val2'."      ]
@@ -15810,7 +15816,7 @@ stdout of test 'MAL-signatures` in direc
 [ "mtime",     "timestamp_sub_msec_interval",  "command 
mtime.timestamp_sub_msec_interval(t:timestamp, ms:lng):timestamp ",    
"MTIMEtimestamp_sub_msec_interval;",    ""      ]
 [ "mtime",     "timestamp_to_str",     "command 
mtime.timestamp_to_str(d:timestamp, format:str):str ", 
"MTIMEtimestamp_to_str;",       "create a string from the time, using the 
specified format (see man strftime)"  ]
 [ "mtime",     "weekofyear",   "command mtime.weekofyear(d:date):int ",        
"MTIMEdate_extract_weekofyear;",        "Returns the week number in the year."  
]
-[ "mtime",     "year", "command mtime.year(d:date):int ",      
"MTIMEdate_extract_year;",      "extracts year from date (nonzero\n\tvalue 
between -5867411 and +5867411)."     ]
+[ "mtime",     "year", "command mtime.year(d:date):int ",      
"MTIMEdate_extract_year;",      "extracts year from date."      ]
 [ "mtime",     "year", "command mtime.year(months:int):int ",  
"MTIMEsql_year;",       ""      ]
 [ "mtime",     "year", "command mtime.year(t:timestamp):int ", 
"MTIMEtimestamp_year;", ""      ]
 [ "netcdf",    "attach",       "pattern netcdf.attach(filename:str):void ",    
"NCDFattach;",  "Register a NetCDF file in the vault"   ]
diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -1486,10 +1486,14 @@ str MTIMEdate_addmonths(date *ret, const
 str MTIMEdate_date(date *dst, const date *src);
 str MTIMEdate_diff(int *ret, const date *v1, const date *v2);
 str MTIMEdate_diff_bulk(bat *ret, bat *bid1, bat *bid2);
+str MTIMEdate_extract_century(int *ret, const date *d);
+str MTIMEdate_extract_century_bulk(bat *ret, bat *bid);
 str MTIMEdate_extract_day(int *ret, const date *d);
 str MTIMEdate_extract_day_bulk(bat *ret, bat *bid);
 str MTIMEdate_extract_dayofweek(int *ret, const date *d);
 str MTIMEdate_extract_dayofyear(int *ret, const date *d);
+str MTIMEdate_extract_decade(int *ret, const date *d);
+str MTIMEdate_extract_decade_bulk(bat *ret, bat *bid);
 str MTIMEdate_extract_month(int *ret, const date *d);
 str MTIMEdate_extract_month_bulk(bat *ret, bat *bid);
 str MTIMEdate_extract_quarter(int *ret, const date *d);
@@ -1529,7 +1533,9 @@ str MTIMEtime_sub_msec_interval(daytime 
 str MTIMEtime_to_str(str *ret, const daytime *d, const char *const *format);
 str MTIMEtimestamp_add_month_interval(timestamp *ret, const timestamp *t, 
const int *m);
 str MTIMEtimestamp_add_msec_interval(timestamp *ret, const timestamp *t, const 
lng *ms);
+str MTIMEtimestamp_century(int *ret, const timestamp *t);
 str MTIMEtimestamp_day(int *ret, const timestamp *t);
+str MTIMEtimestamp_decade(int *ret, const timestamp *t);
 str MTIMEtimestamp_diff_msec(lng *ret, const timestamp *t1, const timestamp 
*t2);
 str MTIMEtimestamp_diff_msec_bulk(bat *ret, bat *bid1, bat *bid2);
 str MTIMEtimestamp_extract_date(date *ret, const timestamp *t);
diff --git a/monetdb5/modules/atoms/mtime.c b/monetdb5/modules/atoms/mtime.c
--- a/monetdb5/modules/atoms/mtime.c
+++ b/monetdb5/modules/atoms/mtime.c
@@ -1005,6 +1005,10 @@ mal_export str MTIMEdaytime_diff_msec(ln
 mal_export str MTIMEtimestamp_diff_msec_bulk(bat *ret, bat *bid1, bat *bid2);
 mal_export str MTIMEdate_submonths(date *ret, const date *d, const int *m);
 mal_export str MTIMEdate_addmonths(date *ret, const date *d, const int *m);
+mal_export str MTIMEdate_extract_century(int *ret, const date *d);
+mal_export str MTIMEdate_extract_century_bulk(bat *ret, bat *bid);
+mal_export str MTIMEdate_extract_decade(int *ret, const date *d);
+mal_export str MTIMEdate_extract_decade_bulk(bat *ret, bat *bid);
 mal_export str MTIMEdate_extract_year(int *ret, const date *d);
 mal_export str MTIMEdate_extract_year_bulk(bat *ret, bat *bid);
 mal_export str MTIMEdate_extract_quarter(int *ret, const date *d);
@@ -1023,6 +1027,8 @@ mal_export str MTIMEdate_extract_dayofye
 mal_export str MTIMEdate_extract_weekofyear(int *ret, const date *d);
 mal_export str MTIMEdate_extract_dayofweek(int *ret, const date *d);
 mal_export str MTIMEtimestamp_diff_msec(lng *ret, const timestamp *t1, const 
timestamp *t2);
+mal_export str MTIMEtimestamp_century(int *ret, const timestamp *t);
+mal_export str MTIMEtimestamp_decade(int *ret, const timestamp *t);
 mal_export str MTIMEtimestamp_year(int *ret, const timestamp *t);
 mal_export str MTIMEtimestamp_quarter(int *ret, const timestamp *t);
 mal_export str MTIMEtimestamp_month(int *ret, const timestamp *t);
@@ -1296,6 +1302,108 @@ MTIMEdate_addmonths(date *ret, const dat
 }
 
 str
+MTIMEdate_extract_century(int *ret, const date *d)
+{
+       if (is_date_nil(*d)) {
+               *ret = int_nil;
+       } else {
+               int y = date_extract_year(*d);
+               if (y > 0)
+                       *ret = (y - 1) / 100 + 1;
+               else
+                       *ret = -((-y - 1) / 100 + 1);
+       }
+       return MAL_SUCCEED;
+}
+
+str
+MTIMEdate_extract_century_bulk(bat *ret, bat *bid)
+{
+       BAT *b, *bn;
+       BUN n;
+       const date *d;
+       int *y;
+
+       if ((b = BATdescriptor(*bid)) == NULL)
+               throw(MAL, "batmtime.century", SQLSTATE(HY002) 
RUNTIME_OBJECT_MISSING);
+       n = BATcount(b);
+       if ((bn = COLnew(b->hseqbase, TYPE_int, n, TRANSIENT)) == NULL) {
+               BBPunfix(b->batCacheid);
+               throw(MAL, "batmtime.century", SQLSTATE(HY001) MAL_MALLOC_FAIL);
+       }
+       d = Tloc(b, 0);
+       y = Tloc(bn, 0);
+       bn->tnil = false;
+       for (BUN i = 0; i < n; i++) {
+               if (is_date_nil(d[i])) {
+                       y[i] = int_nil;
+                       bn->tnil |= is_int_nil(y[i]);
+               } else {
+                       y[i] = date_extract_year(d[i]);
+                       if (y[i] > 0)
+                               y[i] = (y[i] - 1) / 100 + 1;
+                       else
+                               y[i] = -((-y[i] - 1) / 100 + 1);
+               }
+       }
+       bn->tnonil = !bn->tnil;
+       BATsetcount(bn, n);
+       bn->tsorted = b->tsorted;
+       bn->trevsorted = b->trevsorted;
+       bn->tkey = false;
+       BBPunfix(b->batCacheid);
+       BBPkeepref(*ret = bn->batCacheid);
+       return MAL_SUCCEED;
+}
+
+str
+MTIMEdate_extract_decade(int *ret, const date *d)
+{
+       if (is_date_nil(*d)) {
+               *ret = int_nil;
+       } else {
+               *ret = date_extract_year(*d) / 10;
+       }
+       return MAL_SUCCEED;
+}
+
+str
+MTIMEdate_extract_decade_bulk(bat *ret, bat *bid)
+{
+       BAT *b, *bn;
+       BUN n;
+       const date *d;
+       int *y;
+
+       if ((b = BATdescriptor(*bid)) == NULL)
+               throw(MAL, "batmtime.decade", SQLSTATE(HY002) 
RUNTIME_OBJECT_MISSING);
+       n = BATcount(b);
+       if ((bn = COLnew(b->hseqbase, TYPE_int, n, TRANSIENT)) == NULL) {
+               BBPunfix(b->batCacheid);
+               throw(MAL, "batmtime.decade", SQLSTATE(HY001) MAL_MALLOC_FAIL);
+       }
+       d = Tloc(b, 0);
+       y = Tloc(bn, 0);
+       bn->tnil = false;
+       for (BUN i = 0; i < n; i++) {
+               if (is_date_nil(d[i])) {
+                       y[i] = int_nil;
+                       bn->tnil |= is_int_nil(y[i]);
+               } else {
+                       y[i] = date_extract_year(d[i]) / 10;
+               }
+       }
+       bn->tnonil = !bn->tnil;
+       BATsetcount(bn, n);
+       bn->tsorted = b->tsorted;
+       bn->trevsorted = b->trevsorted;
+       bn->tkey = false;
+       BBPunfix(b->batCacheid);
+       BBPkeepref(*ret = bn->batCacheid);
+       return MAL_SUCCEED;
+}
+
+str
 MTIMEdate_extract_year(int *ret, const date *d)
 {
        *ret = date_year(*d);
@@ -1673,6 +1781,32 @@ MTIMEtimestamp_diff_msec_bulk(bat *ret, 
 }
 
 str
+MTIMEtimestamp_century(int *ret, const timestamp *t)
+{
+       if (is_timestamp_nil(*t)) {
+               *ret = int_nil;
+       } else {
+               int y = date_extract_year(ts_date(*t));
+               if (y > 0)
+                       *ret = (y - 1) / 100 + 1;
+               else
+                       *ret = -((-y - 1) / 100 + 1);
+       }
+       return MAL_SUCCEED;
+}
+
+str
+MTIMEtimestamp_decade(int *ret, const timestamp *t)
+{
+       if (is_timestamp_nil(*t)) {
+               *ret = int_nil;
+       } else {
+               *ret = date_extract_year(ts_date(*t)) / 10;
+       }
+       return MAL_SUCCEED;
+}
+
+str
 MTIMEtimestamp_year(int *ret, const timestamp *t)
 {
        *ret = date_year(timestamp_date(*t));
diff --git a/monetdb5/modules/atoms/mtime.mal b/monetdb5/modules/atoms/mtime.mal
--- a/monetdb5/modules/atoms/mtime.mal
+++ b/monetdb5/modules/atoms/mtime.mal
@@ -384,10 +384,21 @@ comment "get the local timezone in secon
 # For decomposing a timestamp, there are routines that decompose it in a date
 # and daytime. The bulk variants are also provided to simplify code
 # generation for SQL and to improve speed.
+command century(d:date) :int
+address MTIMEdate_extract_century
+comment "extracts century from date.";
+command batmtime.century(d:bat[:date]):bat[:int]
+address MTIMEdate_extract_century_bulk;
+
+command decade(d:date) :int
+address MTIMEdate_extract_decade
+comment "extracts decade from date.";
+command batmtime.decade(d:bat[:date]):bat[:int]
+address MTIMEdate_extract_decade_bulk;
+
 command year(d:date) :int
 address MTIMEdate_extract_year
-comment "extracts year from date (nonzero
-       value between -5867411 and +5867411).";
+comment "extracts year from date.";
 command batmtime.year(d:bat[:date]):bat[:int]
 address MTIMEdate_extract_year_bulk;
 
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to