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

时间:2018-05-28 07:32:28

标签: sql subquery amazon-redshift

我遇到了这个错误:

  

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

在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

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

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

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:0)

我特此发布现在有效的更新查询。删除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