DBOS / SPU不支持函数format_type

时间:2015-10-02 02:06:39

标签: sql netezza

我在Neteeza - Aginity

中尝试运行以下查询时遇到主题错误
(SELECT 'TABLE1' AS TABLE_NAME, 'CHANGE_BY_CD' AS COL,(SELECT DATA_TYPE 
FROM information_schema.columns WHERE table_name = 'TABLE1'
AND COLUMN_NAME = 'CHANGE_BY_CD') AS COL_LEN, MAX(LENGTH(CHANGE_BY_CD)) AS MAX_LEN, CHANGE_BY_CD::CHARACTER VARYING(2000) AS VAL FROM SCHEMA1.A_TABLE1 
WHERE CHANGE_BY_CD IS NOT NULL GROUP BY CHANGE_BY_CD ORDER BY MAX_LEN DESC , CHANGE_BY_CD DESC LIMIT 1) 

错误

ERROR:  function format_type not supported on DBOS/SPU

将以下部分添加到查询

后会弹出此错误
(SELECT DATA_TYPE 
FROM information_schema.columns WHERE table_name = 'TABLE1'
AND COLUMN_NAME = 'CHANGE_BY_CD') AS COL_LEN

这是否有任何解决方案

由于

1 个答案:

答案 0 :(得分:1)

您遇到了一个所谓的"桥接查询"的问题,这是一个引用系统目录表(通过视图)和本机Netezza表的查询。在这些类型的查询中,遇到数据类型和功能兼容性问题并不罕见。

不要过于深入到这些杂草中,我会切入追逐并说如果你使用案例陈述来解决数据类型,你可以在这种特殊情况下避免这些问题。

对于CHARACTER,VARCHAR,NCHARACTER和NVARCHAR,您可以从ATTTYPMOD中的值中减去12,以获取DDL中定义的列的字符长度。

SELECT 'TABLE1'   AS TABLE_NAME,
   'CHANGE_BY_CD' AS COL,
   (
      SELECT data_type
      FROM (
            SELECT objname,
               attname,
               atttypid,
               ATT.ATTTYPMOD,
               CASE
                  WHEN atttypid=23 THEN 'INTEGER'
                  WHEN atttypid=16 THEN 'BOOLEAN'
                  WHEN atttypid=17 THEN 'BYTEA' 
                  WHEN atttypid=18 THEN 'CHAR'
                  WHEN atttypid=19 THEN 'NAME'
                  WHEN atttypid=20 THEN 'BIGINT'
                  WHEN atttypid=21 THEN 'SNALLINT'
                  WHEN atttypid=22 THEN 'INT2VECTOR'
                  WHEN atttypid=24 THEN 'REGPROC'
                  WHEN atttypid=25 THEN 'TEXT'
                  WHEN atttypid=26 THEN 'OID'
                  WHEN atttypid=27 THEN 'TID'
                  WHEN atttypid=28 THEN 'XID'
                  WHEN atttypid=29 THEN 'CID'
                  WHEN atttypid=30 THEN 'OIDVECTOR'
                  WHEN atttypid=210 THEN 'SMGR'
                  WHEN atttypid=700 THEN 'REAL'
                  WHEN atttypid=701 THEN 'DOUBLE'
                  WHEN atttypid=702 THEN 'ABSTIME'
                  WHEN atttypid=705 THEN 'UNKNOWN'
                  WHEN atttypid=1007 THEN '_INTEGER'
                  WHEN atttypid=1033 THEN 'ACLITEM'
                  WHEN atttypid=1034 THEN '_ACLITEM'
                  WHEN atttypid=1042 THEN 'CHARACTER(' || atttypmod -12 || ')'
                  WHEN atttypid=1043 THEN 'VARCHAR(' || atttypmod -12 || ')'
                  WHEN atttypid=1082 THEN 'DATE'
                  WHEN atttypid=1083 THEN 'TIME'
                  WHEN atttypid=1184 THEN 'TIMESTAMP'
                  WHEN atttypid=1266 THEN 'TIMETZ'
                  WHEN atttypid=1700 THEN 'NUMERIC'
                  WHEN atttypid=2500 THEN 'BYTEINT'
                  WHEN atttypid=2569 THEN 'NUCL'
                  WHEN atttypid=2570 THEN 'PROT'
                  WHEN atttypid=2522 THEN 'NCHAR(' || atttypmod -12 || ')'
                  WHEN atttypid=2530 THEN 'NVARCHAR(' || atttypmod -12 || ')'
                  WHEN atttypid=278 THEN 'NTEXT'
               END DATA_TYPE
            FROM DEFINITION_SCHEMA."_V_OBJ_RELATION"
               JOIN DEFINITION_SCHEMA."_V_ATTRIBUTE" ATT
               ON ATT.ATTRELID = DEFINITION_SCHEMA."_V_OBJ_RELATION".RELOID
               LEFT JOIN DEFINITION_SCHEMA."_T_ATTRDEF"
               ON (
                     ATT.ATTRELID = DEFINITION_SCHEMA."_T_ATTRDEF".ADRELID
                  AND ATT.ATTNUM  = DEFINITION_SCHEMA."_T_ATTRDEF".ADNUM
                  )
            WHERE (
                  ATT.ATTNUM                              > 0
               AND SUBSTR("NVARCHAR"(ATT.ATTNAME), 1, 1) <> '_'::"NVARCHAR"
               AND OBJTYPE                                ='TABLE'
               )
         )
         foo
      WHERE foo.objname = 'TABLE_1'
      AND foo.ATTNAME   = 'CHANGE_BY_CD'
   )
                                         AS COL_LEN,
   MAX(LENGTH(CHANGE_BY_CD) )            AS MAX_LEN,
   CHANGE_BY_CD::CHARACTER VARYING(2000) AS VAL
FROM TABLE1
WHERE CHANGE_BY_CD IS NOT NULL
GROUP BY CHANGE_BY_CD
ORDER BY MAX_LEN DESC ,
   CHANGE_BY_CD DESC LIMIT 1 ;