Presto - 有什么可以替代 to_char 的,比如 postgresql?

Presto - how is there an alternative to to_char like postgresql?

我需要在 presto 中构建一个可以回顾过去 70 天的查询,我正在使用的 table 正在以 'YYYYMMDD'.[=12= 的格式存储日期]

在 postgresql 中,我可以简单地将 where 子句写成

where date >= to_char(current_date - 70, 'YYYYMMDD')

它会以 YYYYMMDD 格式提取 70 天前的日期。

但是,在 PrestoSQL 中,该函数似乎不存在,是否有替代方法?

你只需要使用日期算法:

where date >= current_date - interval '70' day

我不确定您为什么要在严格日期相关的比较中包含字符串。

您可以使用 date_format() 执行此操作:

where date >= date_format(current_date - interval '70' day, '%Y%m%d')

请注意,将日期存储为字符串根本不是一个好的做法 - 您应该使用正确的 date 类数据类型 - 然后您根本不需要进行转换。