mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 02:44:59 +00:00
FB-1897 The specs for the datetimepart function are, as far as i can tell, identical to the existing datepart function. Per Pat, replaced the datepart function with datetimepart rather than just adding datetimepart as an alias. Made sure existing tests that were using datepart got switched over. Second go at this after sorting out weirdness with git.
70 lines
2.2 KiB
Go
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, datetimepart('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,
|
|
},
|
|
},
|
|
}
|