我只是想知道如何在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;