如何在PostgreSQL服务器端C函数中为数据库NULL创建Datum



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

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

(这是PostgreSQL 12(

0对于许多数据类型都是一个有效值,因此它不起作用。

无论PostgreSQL服务器代码中的Datum为空,都会有一个bool标志(通常称为isnull(,用于指示Datum是否为空。

比较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;

最新更新