datum

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2026 License: Apache-2.0 Imports: 3 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package datum ports PostgreSQL's Datum value model (postgres/src/include/postgres.h, REL_17_6) to Go: the tagless value that every fmgr-callable function consumes and produces. It is the foundation of the gateway's evaluation engine.

Like pgoid, it is a leaf package under the parser tree: the analyzed expression tree's Const node (parser/ast) carries its value as a Datum, and the parser may depend only on itself within go/common, so the one Datum type the parser, catalog and engine share has to live here rather than beside fmgr. Its only dependency is pgoid.

Representation

PostgreSQL's Datum is a uintptr_t that is *either* an inline scalar or a hidden pointer, distinguished only by the caller's static knowledge of the type. That pointer-hidden-in-an-integer trick is illegal under Go's garbage collector, which must be able to find every live pointer. So Datum here is a two-word struct instead of one machine word:

	type Datum struct { val uint64; ptr unsafe.Pointer }

  - By-value types (bool, the integers, float4/float8, OIDs) live in val, with
    ptr nil. Constructing and reading them touches no heap: DatumGetInt32 and
    friends are allocation-free.
  - By-reference types (text, bytea, numeric, ...) put their payload pointer in
    ptr, which the GC can see and keep alive, and fold the payload length into
    val (see BytesGetDatum). This is why the struct is two words rather than
    PostgreSQL's one.

On 64-bit PostgreSQL, USE_FLOAT8_BYVAL makes int64 and float8 pass-by-value; val is 64 bits wide, so this port is unconditionally byval for every scalar up to 64 bits and needs none of upstream's #ifdef USE_FLOAT8_BYVAL branches.

As upstream, NULL is never encoded in a Datum; it rides alongside in a NullableDatum or a separate isnull flag. A zero Datum is a legitimate value (false, 0, InvalidOid), not a NULL sentinel.

Divergence from upstream

No TOAST, no varlena headers: a by-reference Datum's ptr addresses bare payload bytes, never a 1B/4B-header varlena. The length that a varlena header would carry lives in val instead.

The accessor functions below mirror postgres.h one-for-one (same names, same semantics) so that ported fmgr bodies read line-for-line against the C.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DatumGetBool

func DatumGetBool(x Datum) bool

DatumGetBool returns the boolean value of a datum - postgres.h:90. Any nonzero value is true.

func DatumGetBytes

func DatumGetBytes(x Datum) []byte

DatumGetBytes returns the payload of a by-reference Datum built by BytesGetDatum. The result aliases the original backing array; it is not a copy. Calling this on a Datum that was not built by BytesGetDatum (e.g. a by-value scalar, or one from PointerGetDatum, which sets no length) does not return its payload.

func DatumGetFloat4

func DatumGetFloat4(x Datum) float32

DatumGetFloat4 returns the 4-byte floating point value of a datum - postgres.h:458. Upstream reinterprets the datum's low 32 bits as a float4 through a union; the Float32frombits pun is the exact analogue and preserves every bit, including NaN payloads.

func DatumGetFloat8

func DatumGetFloat8(x Datum) float64

DatumGetFloat8 returns the 8-byte floating point value of a datum - postgres.h:494. Bit-preserving pun, as for float4.

func DatumGetInt16

func DatumGetInt16(x Datum) int16

DatumGetInt16 returns the 16-bit integer value of a datum - postgres.h:162.

func DatumGetInt32

func DatumGetInt32(x Datum) int32

DatumGetInt32 returns the 32-bit integer value of a datum - postgres.h:202.

func DatumGetInt64

func DatumGetInt64(x Datum) int64

DatumGetInt64 returns the 64-bit integer value of a datum - postgres.h:385. Unconditionally pass-by-value here; see the package doc on USE_FLOAT8_BYVAL.

func DatumGetPointer

func DatumGetPointer(x Datum) unsafe.Pointer

DatumGetPointer returns the pointer value of a datum - postgres.h:312.

func DatumGetUInt8

func DatumGetUInt8(x Datum) uint8

DatumGetUInt8 returns the 8-bit unsigned integer value of a datum - postgres.h:142.

func DatumGetUInt16

func DatumGetUInt16(x Datum) uint16

DatumGetUInt16 returns the 16-bit unsigned integer value of a datum - postgres.h:182.

func DatumGetUInt32

func DatumGetUInt32(x Datum) uint32

DatumGetUInt32 returns the 32-bit unsigned integer value of a datum - postgres.h:222.

func DatumGetUInt64

func DatumGetUInt64(x Datum) uint64

DatumGetUInt64 returns the 64-bit unsigned integer value of a datum - postgres.h:419.

Types

type Char

type Char = int8

Char is the storage form of PostgreSQL's "char" type (a single byte), distinguished by name from int8 the way upstream's plain C char is distinct from its int8 (== signed char) typedef, even though both are 8-bit signed. It is an alias, not a defined type, so it stays assignment-compatible with int8 and ported fmgr bodies keep reading line-for-line against the C.

The domain is signed: char.c pins char<->int4 conversions to signed char (chartoi4 reinterprets via (int8), so byte 0xFF reads as -1; i4tochar rejects anything outside SCHAR_MIN..SCHAR_MAX - char.c:184,192). Ordering, by contrast, is unsigned: the comparison operators cast to (uint8) at each site (charlt does (uint8) arg1 < (uint8) arg2 - char.c:145). Those comparison functions therefore must apply the uint8 cast explicitly; Char alone does not carry it.

func DatumGetChar

func DatumGetChar(x Datum) Char

DatumGetChar returns the character value of a datum - postgres.h:112. See Char for why the "char" type maps to a signed 8-bit value.

type CommandId

type CommandId uint32

CommandId is a command identifier within a transaction - c.h:666 ("typedef uint32 CommandId").

func DatumGetCommandId

func DatumGetCommandId(x Datum) CommandId

DatumGetCommandId returns the command identifier value of a datum - postgres.h:292.

type Datum

type Datum struct {
	// contains filtered or unexported fields
}

Datum is the tagless value model - postgres.h:64 ("typedef uintptr_t Datum"). See the package doc for why this is a two-word struct rather than a single machine word. The fields are unexported: callers construct and inspect Datums only through the XxxGetDatum / DatumGetXxx accessors, mirroring the way upstream treats a Datum as opaque outside of postgres.h.

func BoolGetDatum

func BoolGetDatum(x bool) Datum

BoolGetDatum returns the datum representation of a boolean - postgres.h:102.

func BytesGetDatum

func BytesGetDatum(b []byte) Datum

BytesGetDatum builds a by-reference Datum whose payload is b's bytes. The backing array is referenced (not copied); ptr keeps it alive for the GC, so the caller must not mutate b while the Datum is in use. An empty or nil b yields the zero Datum.

func CharGetDatum

func CharGetDatum(x Char) Datum

CharGetDatum returns the datum representation of a character - postgres.h:122.

func CommandIdGetDatum

func CommandIdGetDatum(x CommandId) Datum

CommandIdGetDatum returns the datum representation of a command identifier - postgres.h:302.

func Float4GetDatum

func Float4GetDatum(x float32) Datum

Float4GetDatum returns the datum representation of a 4-byte floating point number - postgres.h:475.

func Float8GetDatum

func Float8GetDatum(x float64) Datum

Float8GetDatum returns the datum representation of an 8-byte floating point number - postgres.h:519.

func Int8GetDatum

func Int8GetDatum(x int8) Datum

Int8GetDatum returns the datum representation of an 8-bit integer - postgres.h:132. (Upstream has no DatumGetInt8; DatumGetChar covers the read direction.)

func Int16GetDatum

func Int16GetDatum(x int16) Datum

Int16GetDatum returns the datum representation of a 16-bit integer - postgres.h:172.

func Int32GetDatum

func Int32GetDatum(x int32) Datum

Int32GetDatum returns the datum representation of a 32-bit integer - postgres.h:212.

func Int64GetDatum

func Int64GetDatum(x int64) Datum

Int64GetDatum returns the datum representation of a 64-bit integer - postgres.h:403.

func MultiXactIdGetDatum

func MultiXactIdGetDatum(x MultiXactId) Datum

MultiXactIdGetDatum returns the datum representation of a multixact identifier - postgres.h:282.

func ObjectIdGetDatum

func ObjectIdGetDatum(x Oid) Datum

ObjectIdGetDatum returns the datum representation of an object identifier - postgres.h:252.

func PointerGetDatum

func PointerGetDatum(p unsafe.Pointer) Datum

PointerGetDatum returns the datum representation of a pointer - postgres.h:322.

func TransactionIdGetDatum

func TransactionIdGetDatum(x TransactionId) Datum

TransactionIdGetDatum returns the datum representation of a transaction identifier - postgres.h:272.

func UInt8GetDatum

func UInt8GetDatum(x uint8) Datum

UInt8GetDatum returns the datum representation of an 8-bit unsigned integer - postgres.h:152.

func UInt16GetDatum

func UInt16GetDatum(x uint16) Datum

UInt16GetDatum returns the datum representation of a 16-bit unsigned integer - postgres.h:192.

func UInt32GetDatum

func UInt32GetDatum(x uint32) Datum

UInt32GetDatum returns the datum representation of a 32-bit unsigned integer - postgres.h:232.

func UInt64GetDatum

func UInt64GetDatum(x uint64) Datum

UInt64GetDatum returns the datum representation of a 64-bit unsigned integer - postgres.h:436.

type MultiXactId

type MultiXactId = TransactionId

MultiXactId is a multixact identifier - c.h:662 ("typedef TransactionId MultiXactId"). Upstream makes it an alias of TransactionId, so it is one here too.

type NullableDatum

type NullableDatum struct {
	Value  Datum // FIELDNO_NULLABLE_DATUM_DATUM 0
	IsNull bool  // FIELDNO_NULLABLE_DATUM_ISNULL 1
}

NullableDatum pairs a Datum with its nullness - postgres.h:72. Nullness lives beside the Datum, never inside it: a Datum on its own is always a non-NULL value.

type Oid

type Oid = pgoid.Oid

Oid is PostgreSQL's object identifier, aliased from the leaf pgoid package so a single Oid type flows through the parser, catalog, and eval code - postgres_ext.h:31.

func DatumGetObjectId

func DatumGetObjectId(x Datum) Oid

DatumGetObjectId returns the object identifier value of a datum - postgres.h:242.

type TransactionId

type TransactionId uint32

TransactionId is a transaction identifier - c.h:652 ("typedef uint32 TransactionId").

func DatumGetTransactionId

func DatumGetTransactionId(x Datum) TransactionId

DatumGetTransactionId returns the transaction identifier value of a datum - postgres.h:262.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL