minato_oid (minato v0.18.6)

View Source

PostgreSQL type OIDs and the mapping between an array type and its element type.

OIDs for built-in types are fixed by PostgreSQL and are stable across servers, so they are compiled in as function clauses rather than read from pg_type at connection time. User defined types (enums, composites, domains) get OIDs assigned per database and are not handled here.

OIDs arrive from the server, so every function that takes one is total and answers undefined for an OID minato has no codec for. Names come from your own code, so oid/1 has no such escape and raises on a name that does not exist.

Summary

Types

The name minato uses for a built-in PostgreSQL type.

Functions

The array type OID whose elements are the given scalar type OID.

The element type OID of an array type OID.

Whether the OID names an array type minato knows.

The name of a scalar type OID, or of an array OID as {array, Name}.

Every scalar type name minato has a codec for.

The OID of a named scalar type, or of an array type given as {array, Name}.

Types

name()

-type name() ::
          bool | bytea | int2 | int4 | int8 | float4 | float8 | numeric | text | varchar | json |
          jsonb | uuid | date | time | timestamp | timestamptz.

The name minato uses for a built-in PostgreSQL type.

oid()

-type oid() :: non_neg_integer().

Functions

array_oid/1

-spec array_oid(oid()) -> oid() | undefined.

The array type OID whose elements are the given scalar type OID.

Returns undefined when the OID is not a scalar type minato knows.

1> minato_oid:array_oid(25).
1009

element_oid/1

-spec element_oid(oid()) -> oid() | undefined.

The element type OID of an array type OID.

Returns undefined when the OID is not an array type minato knows.

1> minato_oid:element_oid(1009).
25

is_array(Oid)

-spec is_array(oid()) -> boolean().

Whether the OID names an array type minato knows.

name/1

-spec name(oid()) -> name() | {array, name()} | undefined.

The name of a scalar type OID, or of an array OID as {array, Name}.

Returns undefined for any OID minato has no codec for.

1> minato_oid:name(23).
int4
2> minato_oid:name(1016).
{array,int8}
3> minato_oid:name(2249).
undefined

names()

-spec names() -> [name()].

Every scalar type name minato has a codec for.

oid/1

-spec oid(name() | {array, name()}) -> oid().

The OID of a named scalar type, or of an array type given as {array, Name}.

Raises function_clause for a name that is not a name/0, which can only be a mistake in the calling code.