Liking cljdoc? Tell your friends :D

datahike.pg.types

PostgreSQL type system registry for the PgWire compatibility layer.

Centralizes all type mappings between PostgreSQL OIDs, SQL type names,

Centralizes all type mappings between PostgreSQL OIDs, SQL type names, Datahike value types, and wire protocol format codes.

Authoritative source: PostgreSQL 19devel src/include/catalog/pg_type.dat

Three directions of mapping:

  1. SQL name → Datahike type (for CREATE TABLE)
  2. Datahike type → PG OID (for wire protocol RowDescription)
  3. PG OID → SQL name (for format_type() and information_schema)
  4. SQL name → category (for CAST type classification)
PostgreSQL type system registry for the PgWire compatibility layer.

Centralizes all type mappings between PostgreSQL OIDs, SQL type names,

Centralizes all type mappings between PostgreSQL OIDs, SQL type names,
Datahike value types, and wire protocol format codes.

Authoritative source: PostgreSQL 19devel src/include/catalog/pg_type.dat

Three directions of mapping:
1. SQL name → Datahike type (for CREATE TABLE)
2. Datahike type → PG OID (for wire protocol RowDescription)
3. PG OID → SQL name (for format_type() and information_schema)
4. SQL name → category (for CAST type classification)
raw docstring

array-oid->element-oidclj

Inverse of element-oid->array-oid: T[] OID → T OID.

Inverse of element-oid->array-oid: T[] OID → T OID.
raw docstring

cast-array-elem-kwclj

(cast-array-elem-kw sql-type-name)

For a SQL type name like int[], return the element-type keyword used by PgArray :elem-type (:int8, :text, :bool, etc.). Returns nil for non-array target types.

For a SQL type name like `int[]`, return the element-type keyword
used by PgArray :elem-type (:int8, :text, :bool, etc.). Returns
nil for non-array target types.
raw docstring

cast-bit-typesclj

SQL type names that cast to a PG bit string — emitted as a string of ASCII '0'/'1' characters in PG's text format. pgjdbc's testgetBadBoolean asserts 29::bit(4) serializes as "1101".

SQL type names that cast to a PG bit string — emitted as a string of
ASCII '0'/'1' characters in PG's text format. pgjdbc's testgetBadBoolean
asserts `29::bit(4)` serializes as "1101".
raw docstring

cast-boolean-typesclj

SQL type names that cast to boolean.

SQL type names that cast to boolean.
raw docstring

cast-bytes-typesclj

SQL type names that cast to a byte array.

SQL type names that cast to a byte array.
raw docstring

cast-categoryclj

(cast-category sql-type-name)

Classify a SQL type name for CAST handling. Returns :integer, :float, :text, :boolean, :date, :time, :timestamp, :uuid, :bytes, :array, or nil. :date and :time are checked before :timestamp so callers can emit the display-appropriate Java type (LocalDate / LocalTime vs Instant). Any type-name ending in [] classifies as :array; the element category can be resolved by recursing on the prefix.

Classify a SQL type name for CAST handling.
Returns :integer, :float, :text, :boolean, :date, :time,
:timestamp, :uuid, :bytes, :array, or nil. :date and :time are
checked before :timestamp so callers can emit the
display-appropriate Java type (LocalDate / LocalTime vs Instant).
Any type-name ending in `[]` classifies as :array; the element
category can be resolved by recursing on the prefix.
raw docstring

cast-date-typesclj

SQL type names that cast to a DATE (no time component). Needed because PG's DATE/TIME/TIMESTAMP all serialize differently in text format — e.g. DATE is '2017-03-13', TIME is '14:25:48', TIMESTAMP is '2017-03-13 14:25:48'. Datahike stores them all as :db.type/instant, so the distinction is only preserved through CAST expressions (where we know the target display type).

SQL type names that cast to a DATE (no time component).
Needed because PG's DATE/TIME/TIMESTAMP all serialize differently
in text format — e.g. DATE is '2017-03-13', TIME is '14:25:48',
TIMESTAMP is '2017-03-13 14:25:48'. Datahike stores them all as
:db.type/instant, so the distinction is only preserved through
CAST expressions (where we know the target display type).
raw docstring

cast-float-typesclj

SQL type names that cast to floating point (Clojure double).

SQL type names that cast to floating point (Clojure double).
raw docstring

cast-integer-typesclj

SQL type names that cast to integer (Clojure long).

SQL type names that cast to integer (Clojure long).
raw docstring

cast-text-typesclj

SQL type names that cast to text (Clojure string).

SQL type names that cast to text (Clojure string).
raw docstring

cast-time-typesclj

SQL type names that cast to a TIME (no date component).

SQL type names that cast to a TIME (no date component).
raw docstring

cast-timestamp-typesclj

SQL type names that cast to timestamp/instant.

SQL type names that cast to timestamp/instant.
raw docstring

cast-uuid-typesclj

SQL type names that cast to UUID.

SQL type names that cast to UUID.
raw docstring

decode-numeric-typmodclj

(decode-numeric-typmod typmod)

Inverse of encode-numeric-typmod. Returns [precision scale] or [nil nil] for typmod -1 (unconstrained NUMERIC).

Inverse of `encode-numeric-typmod`. Returns `[precision scale]` or
`[nil nil]` for typmod -1 (unconstrained NUMERIC).
raw docstring

dh-type->oidclj

Map Datahike :db/valueType to PostgreSQL type OID for wire protocol.

Map Datahike :db/valueType to PostgreSQL type OID for wire protocol.
raw docstring

dh-type->pg-nameclj

Map Datahike :db/valueType to PostgreSQL type name string.

Map Datahike :db/valueType to PostgreSQL type name string.
raw docstring

dh-type-for-oidclj

(dh-type-for-oid oid)

Inverse lookup: PG OID → Datahike valueType. Returns nil for unknown OIDs (caller decides fallback).

Inverse lookup: PG OID → Datahike valueType. Returns nil for
unknown OIDs (caller decides fallback).
raw docstring

dh-type-for-sql-nameclj

(dh-type-for-sql-name sql-name)

Return the Datahike valueType for a SQL type name (lowercased).

Return the Datahike valueType for a SQL type name (lowercased).
raw docstring

elem-kw->oidclj

Element-type keyword (as stored on PgArray :elem-type) → OID.

Element-type keyword (as stored on PgArray :elem-type) → OID.
raw docstring

element-oid->array-oidclj

Scalar element OID → corresponding T[] OID.

Scalar element OID → corresponding T[] OID.
raw docstring

encode-numeric-typmodclj

(encode-numeric-typmod precision scale)

Encode PG NUMERIC(precision, scale) → atttypmod integer. Returns -1 when both precision and scale are nil (unconstrained).

Encode PG NUMERIC(precision, scale) → atttypmod integer.
Returns -1 when both precision and scale are nil (unconstrained).
raw docstring

format-typeclj

(format-type type-oid _typmod)

PostgreSQL format_type(oid, typmod) — return type name for an OID.

PostgreSQL format_type(oid, typmod) — return type name for an OID.
raw docstring

infer-oid-from-valueclj

(infer-oid-from-value v)

Infer a PostgreSQL type OID from a Clojure runtime value.

Infer a PostgreSQL type OID from a Clojure runtime value.
raw docstring

oid->elem-kwclj

Inverse of elem-kw->oid.

Inverse of elem-kw->oid.
raw docstring

oid->pg-nameclj

Map PostgreSQL type OID to canonical type name string.

Map PostgreSQL type OID to canonical type name string.
raw docstring

oid->wire-sizeclj

Map OID to type size for RowDescription's typlen field. Positive = fixed size in bytes, -1 = variable length.

Map OID to type size for RowDescription's typlen field.
Positive = fixed size in bytes, -1 = variable length.
raw docstring

oid-boolclj


oid-bool-arrayclj


oid-bpcharclj


oid-bpchar-arrayclj


oid-byteaclj


oid-bytea-arrayclj


oid-dateclj


oid-date-arrayclj


oid-float4clj


oid-float4-arrayclj


oid-float8clj


oid-float8-arrayclj


oid-for-dh-typeclj

(oid-for-dh-type vtype)

Return the PostgreSQL type OID for a Datahike valueType keyword.

Return the PostgreSQL type OID for a Datahike valueType keyword.
raw docstring

oid-int2clj


oid-int2-arrayclj


oid-int4clj


oid-int4-arrayclj


oid-int8clj


oid-int8-arrayclj


oid-intervalclj


oid-jsonclj


oid-json-arrayclj


oid-jsonbclj


oid-jsonb-arrayclj


oid-nameclj


oid-name-arrayclj


oid-numericclj


oid-numeric-arrayclj


oid-oidclj


oid-oid-arrayclj


oid-textclj


oid-text-arrayclj


oid-timeclj


oid-time-arrayclj


oid-timestampclj


oid-timestamp-arrayclj


oid-timestamptzclj


oid-timestamptz-arrayclj


oid-uuidclj


oid-uuid-arrayclj


oid-varcharclj


oid-varchar-arrayclj


parse-array-type-nameclj

(parse-array-type-name s)

Parse a SQL type string for arrays. Returns {:elem <kw> :pg-name "_T" :ndim N} or nil if not an array.

Strips (p,s) typmod, tolerates int ARRAY / int ARRAY[3] (PG's alternative array syntax — the size is informational, PG doesn't enforce it). Element-name is matched against sql-name->elem-kw so we cover every scalar in our registry.

Multi-dim is reflected by :ndim; we accept arbitrary N at parse time (DDL can choose to reject N>1 if it isn't ready to handle them, but the parser doesn't lose information).

"int[]"        → {:elem :int4, :pg-name "_int4", :ndim 1}
"text[][]"     → {:elem :text, :pg-name "_text", :ndim 2}
"int ARRAY"    → {:elem :int4, :pg-name "_int4", :ndim 1}
"int ARRAY[3]" → {:elem :int4, :pg-name "_int4", :ndim 1}
"numeric(p,s)[]" → {:elem :numeric, :pg-name "_numeric", :ndim 1}
Parse a SQL type string for arrays. Returns
`{:elem <kw> :pg-name "_T" :ndim N}` or `nil` if not an array.

Strips `(p,s)` typmod, tolerates `int ARRAY` / `int ARRAY[3]`
(PG's alternative array syntax — the size is informational,
PG doesn't enforce it). Element-name is matched against
`sql-name->elem-kw` so we cover every scalar in our registry.

Multi-dim is reflected by `:ndim`; we accept arbitrary N at parse
time (DDL can choose to reject N>1 if it isn't ready to handle
them, but the parser doesn't lose information).

    "int[]"        → {:elem :int4, :pg-name "_int4", :ndim 1}
    "text[][]"     → {:elem :text, :pg-name "_text", :ndim 2}
    "int ARRAY"    → {:elem :int4, :pg-name "_int4", :ndim 1}
    "int ARRAY[3]" → {:elem :int4, :pg-name "_int4", :ndim 1}
    "numeric(p,s)[]" → {:elem :numeric, :pg-name "_numeric", :ndim 1}
raw docstring

parse-numeric-argsclj

(parse-numeric-args type-str)

Parse the JSqlParser ColDataType string "NUMERIC (10, 2)" (or "DECIMAL(10,2)" etc.) into [precision scale]. Returns [nil nil] when no parens present (plain NUMERIC).

Parse the JSqlParser ColDataType string `"NUMERIC (10, 2)"` (or
`"DECIMAL(10,2)"` etc.) into `[precision scale]`. Returns
`[nil nil]` when no parens present (plain `NUMERIC`).
raw docstring

pg-name->oidclj

Map a PostgreSQL type name (the string stored on :pg/type when the column's original SQL type doesn't match the Datahike valueType 1:1 — e.g. date vs timestamp both collapse to :db.type/instant) back to its wire OID. Used by infer-param-oid-for-column so pgjdbc's ParameterDescription sees the SQL-declared type, not our internal reduction.

Includes paired _T entries for every scalar — _int4 → oid-int4-array, etc. — so an array column's :pg/type (set to _int4 etc. by translate-create-table for int[] columns) resolves directly to its array OID.

Map a PostgreSQL type name (the string stored on :pg/type when
the column's original SQL type doesn't match the Datahike
valueType 1:1 — e.g. `date` vs `timestamp` both collapse to
:db.type/instant) back to its wire OID. Used by
infer-param-oid-for-column so pgjdbc's ParameterDescription sees
the SQL-declared type, not our internal reduction.

Includes paired `_T` entries for every scalar — `_int4` →
oid-int4-array, etc. — so an array column's `:pg/type` (set
to `_int4` etc. by translate-create-table for `int[]` columns)
resolves directly to its array OID.
raw docstring

pg-name-for-dh-typeclj

(pg-name-for-dh-type vtype)

Return the PostgreSQL type name string for a Datahike valueType keyword.

Return the PostgreSQL type name string for a Datahike valueType keyword.
raw docstring

pg-type-catalogclj

Common PostgreSQL types for the pg_type virtual table. Each entry: [oid typname typlen typtype]

Common PostgreSQL types for the pg_type virtual table.
Each entry: [oid typname typlen typtype]
raw docstring

sql-name->dh-typeclj

Map SQL type names (lowercased) to Datahike :db/valueType keywords. Covers all common SQL and PostgreSQL type name variants.

Map SQL type names (lowercased) to Datahike :db/valueType keywords.
Covers all common SQL and PostgreSQL type name variants.
raw docstring

sql-name->elem-kwclj

SQL type name (lowercased, no (p,s) parens) → the array-element keyword used on PgArray :elem-type. More specific than sql-name->dh-type because integer width matters at the wire layer (int4[]_int4, OID 1007; int8[]_int8, OID 1016) even though both reduce to :db.type/long in Datahike storage.

SQL type name (lowercased, no `(p,s)` parens) → the array-element
keyword used on `PgArray :elem-type`. More specific than
`sql-name->dh-type` because integer width matters at the wire
layer (`int4[]` → `_int4`, OID 1007; `int8[]` → `_int8`, OID 1016)
even though both reduce to `:db.type/long` in Datahike storage.
raw docstring

var-hdr-szclj


wire-sizeclj

(wire-size oid)

Return the wire protocol type size for an OID.

Return the wire protocol type size for an OID.
raw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close