我现在正在使用称为 SQL API 的 REST API 从 Snowflake 加载一些数据。问题是在创建响应 JSON 时,Snowflake 对 DATE 类型的字段使用了一些奇怪的格式。
我有这个示例字段元数据:
{
"name" : "...",
"database" : "...",
"schema" : "...",
"table" : "...",
"type" : "date",
"scale" : null,
"precision" : null,
"length" : null,
"collation" : null,
"nullable" : true,
"byteLength" : null
}
在结果集中它的值为 "9245"
。使用浏览器中的查询,我看到实际值为 1995-04-25
。
什么魔法函数将这个整数解码回日期?
答案 0 :(得分:1)
基于文档 Getting the Data From the Results
<块引用>日期
自纪元(例如 18262)以来的天数的整数值(以字符串形式)。
相关:Why is 1/1/1970 the “epoch time”?
检查:
SELECT DATEADD(day, 9245, '1970-01-01'::DATE)
--1995-04-25
SELECT '1970-01-01'::DATE + INTERVAL '9245 DAYS';
-- 1995-04-25