featurebase/sql3/test/defs/defs_timestamp_literals.go
Vengata Krishnan 6777e3dc07
FB-1968 timestamp data type related fixes and enhancements (#2256)
* Removed support for EPOCH column constraint from TIMESTAMP SQL data type.
* Implicit conversion of integers to timestamp will treat the integer value as seconds since unix epoch.
* Add new ToTimeStamp(num, timeunit) SQL scalar function to help convert integer values to timestamp.
2023-02-24 14:57:17 -05:00

70 lines
2.2 KiB
Go

// Copyright 2021 Molecula Corp. All rights reserved.
package defs
var timestampLiterals = TableTest{
Table: tbl(
"testtimestampliterals",
srcHdrs(
srcHdr("_id", fldTypeID),
srcHdr("a", fldTypeInt, "min 0", "max 1000"),
srcHdr("b", fldTypeInt, "min 0", "max 1000"),
srcHdr("d", fldTypeDecimal2),
srcHdr("ts", fldTypeTimestamp),
srcHdr("event", fldTypeStringSet),
srcHdr("ievent", fldTypeIDSet),
),
),
SQLTests: []SQLTest{
{
// InsertWithCurrentTimestamp
SQLs: sqls(
"insert into testtimestampliterals (_id, a, b, d, ts, event, ievent) values (1, 40, 400, 10.12, current_timestamp, ['A', 'B', 'C'], [1, 2, 3])",
),
ExpHdrs: hdrs(),
ExpRows: rows(),
Compare: CompareExactUnordered,
},
{
// InsertWithCurrentDate
SQLs: sqls(
"insert into testtimestampliterals (_id, a, b, d, ts, event, ievent) values (2, 40, 400, 10.12, current_date, ['A', 'B', 'C'], [1, 2, 3])",
),
ExpHdrs: hdrs(),
ExpRows: rows(),
Compare: CompareExactUnordered,
},
{
// Insert literal 0 into a timestamp, it should be stored as 1970-01-01 00:00:00 +0000 UTC (unix epoch base value)
SQLs: sqls(
"insert into testtimestampliterals (_id, a, b, d, ts, event, ievent) values (3, 40, 400, 10.12, 0, ['A', 'B', 'C'], [1, 2, 3])",
),
ExpHdrs: hdrs(),
ExpRows: rows(),
Compare: CompareExactUnordered,
},
{
// Insert literal -86400 into a timestamp, it should be stored as 1969-12-31 00:00:00 +0000 UTC (unix epoch base value)
SQLs: sqls(
"insert into testtimestampliterals (_id, a, b, d, ts, event, ievent) values (4, 40, 400, 10.12, -86400, ['A', 'B', 'C'], [1, 2, 3])",
),
ExpHdrs: hdrs(),
ExpRows: rows(),
Compare: CompareExactUnordered,
},
{
//compare test is done only for integer test cases (_id in (3,4), because only for these cases we have a determinate year(1970, 1969) to look for.
SQLs: sqls(
"select _id, datepart('yy', ts) as \"yy\" from testtimestampliterals where _id in (3,4)",
),
ExpHdrs: hdrs(
hdr("_id", fldTypeID),
hdr("yy", fldTypeInt),
),
ExpRows: rows(
row(int64(3), int64(1970)),
row(int64(4), int64(1969)),
),
Compare: CompareExactUnordered,
},
},
}