【问题标题】:In PostgreSQL, How can I identify a type is composite based on its type Oid in C function?在 PostgreSQL 中,如何根据 C 函数中的类型 Oid 识别类型是复合类型?
【发布时间】:2018-05-14 07:42:08
【问题描述】:

我正在用 PostgreSQL 中的 C 编写一个触发器,它需要根据 pg_type 中的 Oid 来识别类型是否为复合类型。

它是少数不包含在 FormData_pg_attribute 结构中的信息之一。

有人可以帮忙吗?非常感谢。

【问题讨论】:

    标签: c postgresql composite-types


    【解决方案1】:

    你可以这样继续(未经测试):

    #include "access/htup.h"
    #include "catalog/pg_type.h"
    #include "utils/syscache.h"
    
    bool is_composite(Oid typoid)
    {
        HeapTuple   tup;
        Form_pg_type typtup;
        bool result;
    
        tup = SearchSysCache1(TYPEOID, ObjectIdGetDatum(typoid));
        if (!HeapTupleIsValid(tup))
            elog(ERROR, "cache lookup failed for type %u", basetypoid);
        typtup = (Form_pg_type) GETSTRUCT(tup);
    
        result = (typtup->typtype == TYPTYPE_COMPOSITE);
    
        ReleaseSysCache(tup);
    
        return result;
    }
    

    【讨论】:

      猜你喜欢
      • 2021-12-02
      • 2020-06-19
      • 1970-01-01
      • 2016-10-18
      • 1970-01-01
      • 1970-01-01
      • 2021-12-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多