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

标签 c postgresql composite-types

我正在 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/

相关文章:

c - 先声明变量还是直接声明变量,有区别吗?

sql - PostgreSQL:如何访问匿名记录上的列

转换包含十六进制数字的 char*

c - 如何计算给定系列的总和

c - 在没有 LD_PRELOAD 的情况下在用户级别拦截系统调用

postgresql - 从表和所有其他关联表中删除记录

postgresql - 无法使用 Kafka 将数据从 MySQL 流式传输到 Postgres

sql - 在 postgres 中向前(或向后填充)

sql - 复合类型数组上的 SUM 和 GROUP BY