2017-07-06 67 views
0

當我運行下面的查詢,紅移pg_user表拋出無效的操作錯誤的JOIN

select * from stl_query q 
join pg_user u on q.userid = u.usesysid 
where u.usename = 'admin'; 

我得到以下錯誤:

SQL Error [500310] [0A000]: [Amazon](500310) Invalid operation: Specified types or functions (one per INFO message) not supported on Redshift tables.; 

查詢是領導節點上運行。我究竟做錯了什麼?

回答

0

pg_user是領導者節點專用函數,不能與不是領導者節點專用的函數混合使用。

從文檔:

Some Amazon Redshift SQL functions are supported only on the leader node and are not supported on the compute nodes. A query that uses a leader-node function must execute exclusively on the leader node, not on the compute nodes, or it will return an error.

The documentation for each leader-node only function includes a note stating that the function will return an error if it references user-defined tables or Amazon Redshift system tables.

來源:http://docs.aws.amazon.com/redshift/latest/dg/c_SQL_functions_leader_node_only.html

如在方案中變通,就可以生成與pg_user數據,您需要的子集的臨時表,然後再加入到臨時表。

select usesysid 
into temp table tmp_user 
from pg_user 
where usename = 'admin'; 

select * from stl_query q 
inner join tmp_user u on q.userid = u.usesysid; 
相關問題