【发布时间】:2018-05-14 07:42:08
【问题描述】:
我正在用 PostgreSQL 中的 C 编写一个触发器,它需要根据 pg_type 中的 Oid 来识别类型是否为复合类型。
它是少数不包含在 FormData_pg_attribute 结构中的信息之一。
有人可以帮忙吗?非常感谢。
【问题讨论】:
标签: c postgresql composite-types
我正在用 PostgreSQL 中的 C 编写一个触发器,它需要根据 pg_type 中的 Oid 来识别类型是否为复合类型。
它是少数不包含在 FormData_pg_attribute 结构中的信息之一。
有人可以帮忙吗?非常感谢。
【问题讨论】:
标签: c postgresql composite-types
你可以这样继续(未经测试):
#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;
}
【讨论】: