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 ¶
- func DatumGetBool(x Datum) bool
- func DatumGetBytes(x Datum) []byte
- func DatumGetFloat4(x Datum) float32
- func DatumGetFloat8(x Datum) float64
- func DatumGetInt16(x Datum) int16
- func DatumGetInt32(x Datum) int32
- func DatumGetInt64(x Datum) int64
- func DatumGetPointer(x Datum) unsafe.Pointer
- func DatumGetUInt8(x Datum) uint8
- func DatumGetUInt16(x Datum) uint16
- func DatumGetUInt32(x Datum) uint32
- func DatumGetUInt64(x Datum) uint64
- type Char
- type CommandId
- type Datum
- func BoolGetDatum(x bool) Datum
- func BytesGetDatum(b []byte) Datum
- func CharGetDatum(x Char) Datum
- func CommandIdGetDatum(x CommandId) Datum
- func Float4GetDatum(x float32) Datum
- func Float8GetDatum(x float64) Datum
- func Int8GetDatum(x int8) Datum
- func Int16GetDatum(x int16) Datum
- func Int32GetDatum(x int32) Datum
- func Int64GetDatum(x int64) Datum
- func MultiXactIdGetDatum(x MultiXactId) Datum
- func ObjectIdGetDatum(x Oid) Datum
- func PointerGetDatum(p unsafe.Pointer) Datum
- func TransactionIdGetDatum(x TransactionId) Datum
- func UInt8GetDatum(x uint8) Datum
- func UInt16GetDatum(x uint16) Datum
- func UInt32GetDatum(x uint32) Datum
- func UInt64GetDatum(x uint64) Datum
- type MultiXactId
- type NullableDatum
- type Oid
- type TransactionId
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DatumGetBool ¶
DatumGetBool returns the boolean value of a datum - postgres.h:90. Any nonzero value is true.
func DatumGetBytes ¶
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 ¶
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 ¶
DatumGetFloat8 returns the 8-byte floating point value of a datum - postgres.h:494. Bit-preserving pun, as for float4.
func DatumGetInt16 ¶
DatumGetInt16 returns the 16-bit integer value of a datum - postgres.h:162.
func DatumGetInt32 ¶
DatumGetInt32 returns the 32-bit integer value of a datum - postgres.h:202.
func DatumGetInt64 ¶
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 ¶
DatumGetPointer returns the pointer value of a datum - postgres.h:312.
func DatumGetUInt8 ¶
DatumGetUInt8 returns the 8-bit unsigned integer value of a datum - postgres.h:142.
func DatumGetUInt16 ¶
DatumGetUInt16 returns the 16-bit unsigned integer value of a datum - postgres.h:182.
func DatumGetUInt32 ¶
DatumGetUInt32 returns the 32-bit unsigned integer value of a datum - postgres.h:222.
func DatumGetUInt64 ¶
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 ¶
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 ¶
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 ¶
BoolGetDatum returns the datum representation of a boolean - postgres.h:102.
func BytesGetDatum ¶
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 ¶
CharGetDatum returns the datum representation of a character - postgres.h:122.
func CommandIdGetDatum ¶
CommandIdGetDatum returns the datum representation of a command identifier - postgres.h:302.
func Float4GetDatum ¶
Float4GetDatum returns the datum representation of a 4-byte floating point number - postgres.h:475.
func Float8GetDatum ¶
Float8GetDatum returns the datum representation of an 8-byte floating point number - postgres.h:519.
func Int8GetDatum ¶
Int8GetDatum returns the datum representation of an 8-bit integer - postgres.h:132. (Upstream has no DatumGetInt8; DatumGetChar covers the read direction.)
func Int16GetDatum ¶
Int16GetDatum returns the datum representation of a 16-bit integer - postgres.h:172.
func Int32GetDatum ¶
Int32GetDatum returns the datum representation of a 32-bit integer - postgres.h:212.
func Int64GetDatum ¶
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 ¶
ObjectIdGetDatum returns the datum representation of an object identifier - postgres.h:252.
func PointerGetDatum ¶
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 ¶
UInt8GetDatum returns the datum representation of an 8-bit unsigned integer - postgres.h:152.
func UInt16GetDatum ¶
UInt16GetDatum returns the datum representation of a 16-bit unsigned integer - postgres.h:192.
func UInt32GetDatum ¶
UInt32GetDatum returns the datum representation of a 32-bit unsigned integer - postgres.h:232.
func UInt64GetDatum ¶
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 ¶
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 ¶
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.