在PostgreSQL中,如何根据C函数中的Oid类型识别一个类型是复合的?

时间:2018-05-14 07:42:09

标签: c postgresql compositetype

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

这是FormData_pg_attribute结构中未包含的少数信息之一。

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

1 个答案:

答案 0 :(得分: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;
}