简体   繁体   English

Redshift - SELECT 表达式有效,但与表值比较时该表达式不可用

[英]Redshift - SELECT expression works, but that expression is not usable when comparing with table value

I am selecting a value on Redshift that gets me a valid value (the timestamp 7 days before now):我在 Redshift 上选择了一个值,它为我提供了一个有效值(现在 7 天前的时间戳):

SELECT cast(extract (epoch from (NOW() - INTERVAL '7 days') ) as integer) ;

1651401212

However, I'm trying to use it on a query but fails:但是,我试图在查询中使用它但失败了:

SELECT  * from mytable where my_epoch_timestamp > cast(extract (epoch from (NOW() - INTERVAL '7 days') ) as integer)  ;

ERROR: Specified types or functions (one per INFO message) not supported on Redshift tables. 

my_epoch_timestamp column is of type integer, hence the cast on the right side. my_epoch_timestamp column的类型为 integer,因此在右侧进行转换。 The type of the separate selections is integer and hence it should be comparable.单独选择的类型是 integer,因此它应该是可比较的。 Am I hitting some kind of limitation here?我在这里遇到某种限制吗?

Note: I can see that similar approach works in PostgresQL here .注意:我可以看到类似的方法在 PostgresQL here中有效。

Side note: I see that the value itself would probably be better to be precomputed first to keep it as a fixed value to use here, but not sure if engine should do that already.旁注:我发现首先预先计算值本身可能会更好,以将其保留为在这里使用的固定值,但不确定引擎是否应该这样做。 May that be causing the trouble here?这可能会在这里造成麻烦吗?

Oh the "ERROR: Specified types or functions (one per INFO message) not supported on Redshift tables."哦,“错误:Redshift 表不支持指定的类型或函数(每个 INFO 消息一个)。” error.错误。 This has to be one of the worst written error messages in existence.这一定是现存最糟糕的书面错误消息之一。 This error means that the query tried to moved data from the leader node to the compute nodes which is an unsupported path.此错误意味着查询试图将数据从领导节点移动到计算节点,这是一条不受支持的路径。 It can crop up in a number of ways but in your case it is the NOW() function. NOW() is a leader only functions as it returns the time that the transaction began (if memory serves correctly) which is kept on the leader node.它可以以多种方式出现,但在您的情况下,它是 NOW() function。NOW() 是一个领导者,仅在它返回交易开始的时间(如果 memory 服务正确)时保留在领导者上节点。 GETDATE() is provides the time that the query runs and is available on the compute nodes. GETDATE() 提供查询运行的时间并在计算节点上可用。 If this slight difference in meaning isn't important to your process (and it usually isn't), just replace NOW() with GETDATE() and you should be good to go.如果这种意义上的细微差异对您的过程并不重要(通常情况下并不重要),只需将 NOW() 替换为 GETDATE() 即可,您应该可以使用 go。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM