Redshift中date_trunc()返回的奇怪错误

Jas*_*ine 4 sql amazon-redshift

所以我在Redshift数据库上遇到以下奇怪的行为.

以下查询按预期运行将当前时间戳截断为月份:

select date_trunc('month', now()) -- returns 2019-01-01 00:00:00+00
Run Code Online (Sandbox Code Playgroud)

相反这个查询:

select date_trunc('month', now())
from table
Run Code Online (Sandbox Code Playgroud)

返回以下错误

错误:Redshift表不支持指定的类型或函数(每个INFO消息一个).

没有INFO消息,但显然问题与date_trunc()它有关,因为它是唯一使用的功能.

通常情况下,我希望它能像在PostgreSQL上一样工作,将截断的当前时间戳返回到月份的行数table.

我还采取一看这个情况下date_trunc()还没有完全支持,但我找不到任何引用.

有什么我想念的吗?任何解决方法?

Jon*_*ott 6

now()是一个仅限领导节点的函数.这意味着如果你不使用表,它就可以工作.

而不是now(),您可以使用current_timestamp

例如

select date_trunc('month', current_timestamp)
from table;
Run Code Online (Sandbox Code Playgroud)

这样可以正常工作.

请参阅https://docs.aws.amazon.com/redshift/latest/dg/Date_functions_header.html

(在底部)