Netezza中的错误时间戳外部表示错误

时间:2015-09-06 11:35:55

标签: sql netezza

我在Netezza的查询下面运行并且提到了错误。

查询:

SELECT * FROM WORKORDER SRC  
    INNER JOIN  APPOINTMENT TRG
        ON SRC.ACCESSID = TRG.SEEKER_ID 
        AND (COALESCE(SRC.SLAEXPIRY, '') = COALESCE(TRG.SLA_EXPIRY_DATE_TS, ''))

错误:

ERROR [HY000] ERROR:  Bad timestamp external representation ''

正如我可以看到有NULLSLAEXPIRY列的SLA_EXPIRY_DATE_TS值尝试以下选项,但没有运气

SELECT * FROM WORKORDER SRC  
    INNER JOIN  APPOINTMENT TRG
        ON SRC.ACCESSID = TRG.SEEKER_ID 
        AND case when COALESCE(SRC.SLAEXPIRY, '') is not null then COALESCE(SRC.SLAEXPIRY, '')
                            else NULL end = case when COALESCE(TRG.SLA_EXPIRY_DATE_TS, '') is not null then COALESCE(TRG.SLA_EXPIRY_DATE_TS, '')
                                            else NULL end

1 个答案:

答案 0 :(得分:1)

这里的根本问题是空字符串(即'')不能转换为时间戳。

TESTDB.ADMIN(ADMIN)=> select coalesce(current_timestamp, '');
ERROR:  Bad timestamp external representation ''

第二个问题当然是NULL不加入。如果您想要加入NULL,以下查询应该适合您。不要指望这种基于表达式的连接能有很好的表现。

SELECT *
FROM WORKORDER SRC
   INNER JOIN APPOINTMENT TRG
   ON SRC.ACCESSID = TRG.SEEKER_ID
   AND
      (
         (
            SRC.SLAEXPIRY = TRG.SLA_EXPIRY_DATE_TS
         )
      OR
         (
            SRC.SLAEXPIRY           IS NULL
         AND TRG.SLA_EXPIRY_DATE_TS IS NULL
         )
      )