pg: timestamp(tz) types + more docs

This commit is contained in:
Yorhel 2025-02-21 12:58:24 +01:00
parent 8036b8f0bf
commit 6f1583ddad
3 changed files with 121 additions and 5 deletions

View file

@ -486,6 +486,23 @@ SENDFN(uuid) {
if (dig != 0x10 || bytes != 16) SERR("invalid UUID");
}
/* Postgres uses 2000-01-01 as epoch, we stick with POSIX 1970-01-01 */
#define UNIX_PG_EPOCH (10957*86400)
RECVFN(timestamp) {
RLEN(8);
IV ts = fu_frombeI(64, buf);
return newSVnv(((double)ts / 1000000) + UNIX_PG_EPOCH);
}
SENDFN(timestamp) {
if (!looks_like_number(val)) SERR("expected a number");
IV ts = (SvNV(val) - UNIX_PG_EPOCH) * 1000000;
fustr_writebeI(64, out, ts);
}
#undef UNIX_PG_EPOCH
#undef SIV
#undef RLEN
#undef RECVFN
@ -590,11 +607,11 @@ SENDFN(uuid) {
B( 1043, "varchar", text )\
/* 1082 date */\
/* 1083 time */\
B( 1114, "timestamp", timestamp)\
A( 1115, "_timestamp", 1114 )\
/* 1114 timestamp */\
A( 1182, "_date", 1082 )\
A( 1183, "_time", 1083 )\
/* 1184 timestamptz */\
B( 1184, "timestamptz", timestamp)\
A( 1185, "_timestamptz", 1184 )\
/* 1186 interval */\
A( 1187, "_interval", 1186 )\