“频谱嵌套查询错误” Redshift错误

当我在Redshift中运行此查询时:

select sd.device_id
from devices.s_devices sd
left join devices.c_devices cd
on sd.device_id = cd.device_id

我收到这样的错误:

ERROR:  Spectrum nested query error
DetaIL:  
  -----------------------------------------------
  error:  Spectrum nested query error
  code:      8001
  context:   A subquery that refers to a nested table cannot refer to any other table.
  query:     0
  location:  nested_query_rewriter.cpp:726
  process:   padbmaster [pid=6361]
  -----------------------------------------------

我不太确定此错误是什么意思。我只加入一个表,不确定该表指的是“另一个表”,在网络上找不到关于此错误的更多信息。

我注意到,如果将其从left join更改为join,该错误会消失,但是我确实需要进行左连接。

有什么想法我在做什么错吗?

iCMS 回答:“频谱嵌套查询错误” Redshift错误

Redshift reference提到:

如果子查询中的FROM子句引用嵌套表,则它不能引用任何其他表。

在您的示例中,您试图在一个语句中连接两个嵌套列。

我会尝试先取消嵌套,然后再加入:

with 
    s_dev as (select sd.device_id from devices.s_devices sd),c_dev as (select cd.device_id from devices.c_devices cd)
select 
    c_dev.device_id
from c_dev 
    left join s_dev 
        on s_dev.device_id = c_dev.device_id

 
,

对我有用的解决方案是使用嵌套表的数据创建一个临时表,然后将临时表与我需要的其余表连接起来。

例如,如果嵌套表是spectrum.customers,则解决方案是:

 DROP TABLE IF EXISTS temp_spectrum_customers;

 CREATE TEMPORARY TABLE
     temp_spectrum_customers AS
 SELECT c.id,o.shipdate,c.customer_id
 FROM spectrum.customers c,c.orders o;

 SELECT tc.id,tc.shipdate,tc.customer_id,d.delivery_carrier
 FROM temp_spectrum_customers tc
          LEFT OUTER JOIN orders_delivery d on tc.id = d.order_id;
本文链接:https://www.f2er.com/1679580.html

大家都在问