首页 > 解决方案 > 由于内部错误,不支持相关子查询模式的类型

问题描述

我遇到了这个错误:

“由于内部错误,不支持这种类型的相关子查询模式”

在 Matillion(Redshift 的 ETL 工具)上执行以下查询时。

SELECT DISTINCT
  "sap"."tracking_no" AS "tracking_no",
  (select case when len("sap"."order_create_time")=6 and
                 regexp_instr("sap"."order_create_date",'[a-zA-Z]')=0 and 
                 regexp_instr("sap"."order_create_time",'[a-zA-Z]')=0
            then CAST(CONCAT(CONCAT(cast(isnull("sap"."order_create_date",'1900-01-01') as VARCHAR(10)), ' '),
                   CONCAT(CONCAT(CONCAT(CONCAT(SUBSTRING(isnull("sap"."order_create_time",'000000'), 1,2), ':'),
                   SUBSTRING(isnull("sap"."order_create_time",'000000'), 3,2)),':'),
                   SUBSTRING(isnull("sap"."order_create_time",'000000'), 5,2))) as timestamp)
            when len("sap"."order_create_time")=5 and regexp_instr("sap"."order_create_date",'[a-zA-Z]')=0 and 
                 regexp_instr("sap"."order_create_time",'[a-zA-Z]')=0
            then  CAST(CONCAT(CONCAT(cast(isnull("sap"."order_create_date",'1900-01-01') as VARCHAR(10)), ' '),
                       CONCAT(CONCAT(CONCAT(CONCAT(concat('0',SUBSTRING(isnull("sap"."order_create_time",'000000'), 5,1)), ':'),
                       SUBSTRING(isnull("sap"."order_create_time",'000000'), 3,2)),':'),
                       SUBSTRING(isnull("sap"."order_create_time",'000000'), 5,1))) as timestamp)
            else cast('1900-01-01 000000' as timestamp)
   end)  as "order_date_time",
   (select case when len("sap"."ship_time")=6 and
                 regexp_instr("sap"."ship_date",'[a-zA-Z]')=0 and 
                 regexp_instr("sap"."ship_time",'[a-zA-Z]')=0
            then CAST(CONCAT(CONCAT(cast(isnull("sap"."ship_date",'1900-01-01') as VARCHAR(10)), ' '),
                   CONCAT(CONCAT(CONCAT(CONCAT(SUBSTRING(isnull("sap"."ship_time",'000000'), 1,2), ':'),
                   SUBSTRING(isnull("sap"."ship_time",'000000'), 3,2)),':'),
                   SUBSTRING(isnull("sap"."ship_time",'000000'), 5,2))) as timestamp)
            when len("sap"."ship_time")=5 and regexp_instr("sap"."ship_date",'[a-zA-Z]')=0 and 
                 regexp_instr("sap"."ship_time",'[a-zA-Z]')=0
            then  CAST(CONCAT(CONCAT(cast(isnull("sap"."ship_date",'1900-01-01') as VARCHAR(10)), ' '),
                       CONCAT(CONCAT(CONCAT(CONCAT(concat('0',SUBSTRING(isnull("sap"."ship_time",'000000'), 5,1)), ':'),
                       SUBSTRING(isnull("sap"."ship_time",'000000'), 3,2)),':'),
                       SUBSTRING(isnull("sap"."ship_time",'000000'), 5,1))) as timestamp)
            else cast('1900-01-01 000000' as timestamp)
end)  as "ship_date_time",
  "fedex"."TRACKING_NUMBER" AS "TRACKING_NUMBER"      
FROM fed_ex_feed AS "fedex"
     LEFT OUTER JOIN     
     sap_delivery AS "sap" 
     ON "fedex"."TRACKING_NUMBER" = "sap"."tracking_no"
WHERE sap.order_create_date is not null and
      fedex.DELIVERY_DATE is not null

我尝试搜索分辨率,但在互联网上找不到任何分辨率。

它是否与红移集群有关,因为它暗示为内部错误?

任何帮助,将不胜感激。

标签: sqlsubqueryamazon-redshift

解决方案


我特此发布更新后的查询,该查询现在有效。删除select前面的语句,case它就可以工作了。

SELECT DISTINCT
  "sap"."tracking_no" AS "tracking_no",
   case when len("sap"."order_create_time")=6 and
                 regexp_instr("sap"."order_create_date",'[a-zA-Z]')=0 and 
                 regexp_instr("sap"."order_create_time",'[a-zA-Z]')=0
            then CAST(CONCAT(CONCAT(cast(isnull("sap"."order_create_date",'1900-01-01') as VARCHAR(10)), ' '),
                   CONCAT(CONCAT(CONCAT(CONCAT(SUBSTRING(isnull("sap"."order_create_time",'000000'), 1,2), ':'),
                   SUBSTRING(isnull("sap"."order_create_time",'000000'), 3,2)),':'),
                   SUBSTRING(isnull("sap"."order_create_time",'000000'), 5,2))) as timestamp)
            when len("sap"."order_create_time")=5 and regexp_instr("sap"."order_create_date",'[a-zA-Z]')=0 and 
                 regexp_instr("sap"."order_create_time",'[a-zA-Z]')=0
            then  CAST(CONCAT(CONCAT(cast(isnull("sap"."order_create_date",'1900-01-01') as VARCHAR(10)), ' '),
                       CONCAT(CONCAT(CONCAT(CONCAT(concat('0',SUBSTRING(isnull("sap"."order_create_time",'000000'), 5,1)), ':'),
                       SUBSTRING(isnull("sap"."order_create_time",'000000'), 3,2)),':'),
                       SUBSTRING(isnull("sap"."order_create_time",'000000'), 5,1))) as timestamp)
            else cast('1900-01-01 000000' as timestamp)
   end  as "order_date_time"
   , case when len("sap"."ship_time")=6 and
                 regexp_instr("sap"."ship_date",'[a-zA-Z]')=0 and 
                 regexp_instr("sap"."ship_time",'[a-zA-Z]')=0
            then CAST(CONCAT(CONCAT(cast(isnull("sap"."ship_date",'1900-01-01') as VARCHAR(10)), ' '),
                   CONCAT(CONCAT(CONCAT(CONCAT(SUBSTRING(isnull("sap"."ship_time",'000000'), 1,2), ':'),
                   SUBSTRING(isnull("sap"."ship_time",'000000'), 3,2)),':'),
                   SUBSTRING(isnull("sap"."ship_time",'000000'), 5,2))) as timestamp)
            when len("sap"."ship_time")=5 and regexp_instr("sap"."ship_date",'[a-zA-Z]')=0 and 
                 regexp_instr("sap"."ship_time",'[a-zA-Z]')=0
            then  CAST(CONCAT(CONCAT(cast(isnull("sap"."ship_date",'1900-01-01') as VARCHAR(10)), ' '),
                       CONCAT(CONCAT(CONCAT(CONCAT(concat('0',SUBSTRING(isnull("sap"."ship_time",'000000'), 5,1)), ':'),
                       SUBSTRING(isnull("sap"."ship_time",'000000'), 3,2)),':'),
                       SUBSTRING(isnull("sap"."ship_time",'000000'), 5,1))) as timestamp)
            else cast('1900-01-01 000000' as timestamp)
end  as "ship_date_time",
  "fedex"."TRACKING_NUMBER" AS "TRACKING_NUMBER"      
FROM fed_ex_feed AS "fedex"
     LEFT OUTER JOIN     
     sap_delivery AS "sap" 
     ON "fedex"."TRACKING_NUMBER" = "sap"."tracking_no"
WHERE sap.order_create_date is not null and
      fedex.DELIVERY_DATE is not null

推荐阅读