You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

从SAS向Greenplum发送查询时出现"type character varying is not composite"错误

排查SAS连接Greenplum时偶发的"type character varying is not composite"错误

问题场景

通过SAS脚本向Greenplum提交如下CREATE TABLE AS SELECT语句(使用connection to gp远程查询方式)时,偶发类型错误:

执行的SQL语句

create table new as 
select contact_id 
from connection to gp 
(   select c6.contact_id 
    from PRD_T_CDM.contacts c6, PRD_T_CDM.offers o6 
    where c6.channel_cd = 'OB:SASMA_OFFER' and c6.status = 6 and c6.processed_DTTM between 
    to_timestamp('2023-04-04 02:46:49', 'YYYY-MM-DD HH24:MI:SS') - interval '20' day and current_date 
    and c6.offer_id = o6.offer_id and exists 
    (   select 1 
        from PRD_T_CDM.contacts c5, PRD_T_CDM.offers o5 
        where c5.offer_id = o5.offer_id and 
        ( 
            ( c5.sappn = c6.sappn and o5.campaign_cd = o6.campaign_cd and trim(effort_product) != '778' ) 
            or 
            ( c5.offer_id = c6.offer_id and trim(effort_product) = '778' ) 
        ) 
        and c5.channel_cd = 'OB:SASMA_OFFER' and c5.status = 5 and c5.processed_DTTM 
        between to_timestamp('2023-04-04 02:46:49', 'YYYY-MM-DD HH24:MI:SS') - interval '20' day and current_date 
    ) 
);

错误信息

ERROR: CLI open cursor error: [SAS][ODBC Greenplum Wire Protocol driver][Greenplum]ERROR: type character varying is not composite  
       (seg0 slice2 10.84.168.188:10000 pid=13059)(File typcache.c; Line 758; Routine lookup_rowtype_tupdesc_internal; )

单独直接执行该SQL语句多次均正常,未手动创建过复合类型。

排查与解决方向

  • ODBC驱动兼容性与配置问题
    偶发错误大概率和SAS使用的Greenplum ODBC驱动有关,建议:

    • 升级到与Greenplum集群版本匹配的最新ODBC驱动,修复已知的元数据解析bug;
    • 调整驱动配置,尝试关闭UseDeclareFetch参数(该参数在部分场景下会导致结果集元数据识别异常)。
  • 显式指定字段类型,避免类型映射冲突
    SAS通过远程连接执行查询时,可能偶发类型映射错误,可尝试:

    • 在远程查询中显式指定字段类型,比如将select c6.contact_id改为select c6.contact_id::varchar as contact_id;
    • 拆分查询逻辑:先在Greenplum中创建临时表存储查询结果,再从临时表读取数据到SAS,减少跨系统的类型解析环节。
  • Greenplum类型缓存异常修复
    错误来自Greenplum的类型缓存模块(typcache.c),可尝试:

    • 执行SELECT pg_typcache_clear();手动刷新Greenplum的类型缓存;
    • 查看seg节点的Greenplum日志,定位是否是特定节点的缓存出现损坏,必要时重启该seg节点。
  • 修改SAS的查询提交方式
    替换connection to gp的远程查询方式,尝试:

    • 使用LIBNAME直接连接Greenplum库,然后直接执行CREATE TABLE语句;
    • 将SQL语句保存为外部文件,通过SAS的proc sql调用外部文件执行,减少SAS对SQL语句的额外解析。

内容的提问来源于stack exchange,提问作者Senya Zaitsev

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 14:52:50