gpt4 book ai didi

postgresql - 如何在服务器端 C 函数的 PostgreSQL 中为数据库 NULL 创建数据?

转载 作者:行者123 更新时间:2023-12-04 10:12:02 25 4
gpt4 key购买 nike

我只是想知道如何为数据库创建 Datum NULL PostgreSQL 中的值(value)?

我知道有 PG_RETURN_NULL()用于在 LANGUAGE C 中返回数据库 NULL功能。但我只想为 NULL 创建一个 Datum ,例如存储在数组(或记录)中。我应该只使用 (Datum) 0 ?

(这是 PostgreSQL 12)

最佳答案

0 是许多数据类型的有效值,因此不起作用。

无论您在哪里可以为空 Datum在 PostgreSQL 服务器代码中,您还有一个 bool标志(通常称为 isnull )表示 Datum是否为 NULL。

比较来自 src/include/postgres.h 的以下定义:

/*
* A NullableDatum is used in places where both a Datum and its nullness needs
* to be stored. This can be more efficient than storing datums and nullness
* in separate arrays, due to better spatial locality, even if more space may
* be wasted due to padding.
*/
typedef struct NullableDatum
{
#define FIELDNO_NULLABLE_DATUM_DATUM 0
Datum value;
#define FIELDNO_NULLABLE_DATUM_ISNULL 1
bool isnull;
/* due to alignment padding this could be used for flags for free */
} NullableDatum;

关于postgresql - 如何在服务器端 C 函数的 PostgreSQL 中为数据库 NULL 创建数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61289428/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com