从 Snowflake 中的时间戳获取日期的 trunc 等价物是什么?
What is the equivalent of trunc to get a date from timestamp in Snowflake?
我的组织正在从 Redshift 过渡到 Snowflake,我想问一下是否有更简洁的方法来截断时间戳字段以仅提取其中的日期,就像我在 Redshift 中所做的那样。
当前最佳 Snowflake 查询
select cast (date_trunc('day',max(my_timestamp)) as date) from my_table
等效的 Redshift 查询
select trunc(my_timestamp) from my_table
当然不应该这么丑吧?
谢谢!
Snowflake 使用 Postgres ::
转换值的约定,因此您可以使用:
select date_trunc('day', max(my_timestamp))::date
from my_table;
我没看出这有什么不雅之处。
你可以投到日期
select max(my_timestamp)::date
from my_table;
以下好像是你需要的。
select to_date(max(my_timestamp)) from my_table;
Snowflake 文档指向 TO_DATE 函数,请参阅 here
我的组织正在从 Redshift 过渡到 Snowflake,我想问一下是否有更简洁的方法来截断时间戳字段以仅提取其中的日期,就像我在 Redshift 中所做的那样。
当前最佳 Snowflake 查询
select cast (date_trunc('day',max(my_timestamp)) as date) from my_table
等效的 Redshift 查询
select trunc(my_timestamp) from my_table
当然不应该这么丑吧?
谢谢!
Snowflake 使用 Postgres ::
转换值的约定,因此您可以使用:
select date_trunc('day', max(my_timestamp))::date
from my_table;
我没看出这有什么不雅之处。
你可以投到日期
select max(my_timestamp)::date
from my_table;
以下好像是你需要的。
select to_date(max(my_timestamp)) from my_table;
Snowflake 文档指向 TO_DATE 函数,请参阅 here