我正在 PostgreSQL 中用 C 编写一个触发器,需要根据 pg_type 中的 Oid 来识别该类型是否是复合类型。
它是 FormData_pg_attribute 结构中不包含的少数信息之一。
有人可以帮忙吗?非常感谢。
最佳答案
您可以像这样继续(未经测试):
#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;
}
关于c - 在 PostgreSQL 中,如何根据 C 函数中的类型 Oid 来识别类型是复合类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50325282/