async_postgres/pg_types/array

Types

PgArray[T] = object
  dims*: seq[int32]
  lowerBounds*: seq[int32]
  elements*: seq[Option[T]]

N-dimensional PostgreSQL array value.

dims.len is the number of dimensions. dims.len == 0 represents an empty array (PostgreSQL ndim=0); otherwise elements holds the values in row-major (lexicographic) order with elements.len == product(dims). lowerBounds.len always equals dims.len; the default lower bound for each dimension is 1, matching PostgreSQL's default. NULL elements are represented as none(T).

Consts

PgArrayMaxDim = 6'i32
Maximum number of array dimensions supported, matching PostgreSQL's MAXDIM (src/include/c.h). Both the encoder and the decoder reject arrays whose ndim exceeds this value.

Procs

proc `$`[T](v: PgArray[T]): string
proc `==`[T](a, b: PgArray[T]): bool
proc expectedElemCount(dims: openArray[int32]): int {....raises: [PgTypeError],
    tags: [], forbids: [].}
Compute the expected number of elements for an array with the given dimensions. By convention dims.len == 0 returns 0 (empty array marker); otherwise returns product(dims). Raises PgTypeError on any per-dim length <= 0 (PostgreSQL represents empty arrays with ndim == 0 rather than a zero-sized dimension), or when the product would exceed int32.high (PostgreSQL's wire format uses int32 for element counts). PgTypeError derives from PgError so existing except PgError callers keep working.
proc isEmpty[T](v: PgArray[T]): bool {.inline.}
Whether v is the empty array (dims.len == 0).
proc ndim[T](v: PgArray[T]): int {.inline.}
Number of dimensions. 0 for an empty array.
proc pgArray[T](dims, lowerBounds: openArray[int32];
                elements: openArray[Option[T]]): PgArray[T]
Construct an N-dimensional PgArray with explicit lowerBounds (one per dimension). elements must be in row-major order with elements.len == product(dims).
proc pgArray[T](dims: openArray[int32]; elements: openArray[Option[T]]): PgArray[
    T]
Construct an N-dimensional PgArray from elements that may be NULL. elements must be in row-major order with elements.len == product(dims). lowerBounds defaults to 1 for each dimension.
proc pgArray[T](dims: openArray[int32]; elements: openArray[T]): PgArray[T]
Construct an N-dimensional PgArray from non-NULL elements. elements must be in row-major order with elements.len == product(dims). lowerBounds defaults to 1 for each dimension.
proc pgArray[T](elements: openArray[Option[T]]): PgArray[T]
Construct a 1-dimensional PgArray from elements that may be NULL. An empty elements produces an empty array (dims = @[]). Raises PgTypeError when elements.len > int32.high.
proc pgArray[T](elements: openArray[T]): PgArray[T]
Construct a 1-dimensional PgArray from non-NULL elements. An empty elements produces an empty array (dims = @[]). Raises PgTypeError when elements.len > int32.high (PostgreSQL's wire format uses int32 for element counts).
proc validate[T](v: PgArray[T])
Validate that v is internally consistent.
proc validatePgArrayShape(dims, lowerBounds: openArray[int32]; elementsLen: int) {.
    ...raises: [PgTypeError], tags: [], forbids: [].}
Validate dims/lowerBounds/elements shape consistency for an N-dimensional array. Raises PgTypeError on mismatch, exceeded PgArrayMaxDim, element-count overflow, or any per-dim length <= 0 when dims.len > 0 (PostgreSQL represents empty arrays with ndim == 0 rather than a zero-sized dimension). PgTypeError derives from PgError so existing except PgError callers keep working.