catalog

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 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.

README

catalog

Static pg_catalog (types, functions, operators, casts, aggregates, ranges, and the system relations) embedded as TSV. This is what the analyzer resolves against; user schema is layered on top elsewhere.

System relations (pg_class.tsv, one row per column): every pg_catalog and information_schema table / view with its columns' types and NOT NULL, so SELECT relname FROM pg_class or a query over information_schema.columns types like any table. information_schema's domains (sql_identifier, cardinal_number, ...) ride along in pg_type.tsv with their schema; they resolve only qualified, as in PG. schema.findRelation consults these after the user's relations of the search path (pg_catalog implicitly first, as PG does).

Extensions: data/ext/<name>/ holds the same six TSVs plus META (version, schema, requires) for one extension, dumped from a fresh database right after CREATE EXTENSION ... CASCADE (so a dump bundles what it requires). catalog.WithExtensions(names) merges them on load, renumbering their OIDs into a per-extension range (extBase) so they never meet user objects; Type.Schema / Func.Schema / Operator.Schema keep the namespace they were created in ("" = pg_catalog). schema.LoadWith calls it for every CREATE EXTENSION in schema.sql; one without a dump is a schema problem. Dumped so far: btree_gin, btree_gist, citext, cube, earthdistance, fuzzystrmatch, hstore, intarray, isn, ltree, pg_trgm, pgcrypto, seg, tablefunc, unaccent, uuid-ossp.

  • One directory per PostgreSQL major version: data/<major>/ holds VERSION, the bootstrap TSVs and ext/. A schema's -- sqlshape: postgres <N> picks the directory (catalog.Load(major)).
  • Regenerate: go run ./internal/catalog/gen -pg 18 (boots the oracle PG of that major, COPY ... TO STDOUT, writes data/18/*.tsv + data/18/VERSION); -ext <name> (repeatable) dumps an extension, -all-ext every extension the default version has, -list shows what the oracle binary ships
  • Load: catalog.Load(major) parses once per process per version (~10 ms); lookups by OID / name / (source,target) pair
  • Column order in the TSVs is the contract between gen/main.go and catalog.go

Documentation

Overview

Package catalog is the static PostgreSQL system catalog (pg_catalog objects) the analyzer resolves types, functions, operators and casts against.

The data is dumped from the oracle's PostgreSQL by ./gen and embedded as TSV. User schema (tables, enums, domains, views, functions) is layered on top at analysis time by a separate package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Available

func Available(major int) []string

Available lists the extensions with an embedded dump for a PostgreSQL major version.

func Majors added in v1.2.0

func Majors() []int

Majors lists the PostgreSQL major versions with an embedded catalog, ascending.

Types

type Aggregate

type Aggregate struct {
	FnOID      OID
	Kind       byte // n normal, o ordered-set, h hypothetical-set
	NDirectArg int16
	TransType  OID
}

Aggregate is a row of pg_aggregate.

type Cast

type Cast struct {
	OID     OID
	Source  OID
	Target  OID
	Func    OID  // 0 for binary-coercible / I/O casts
	Context byte // e explicit only, a assignment, i implicit
	Method  byte // f function, b binary coercible, i I/O conversion
}

Cast is a row of pg_cast.

type Catalog

type Catalog struct {
	// Major is the PostgreSQL major version the catalog was dumped from; Version the
	// release ("17.5").
	Major   int
	Version string
	// Extensions are the extensions merged in (WithExtensions), in load order.
	Extensions []*Extension

	Types      []Type
	Funcs      []Func
	Operators  []Operator
	Casts      []Cast
	Aggregates []Aggregate
	Ranges     []Range
	// Relations are the system tables and views (pg_catalog, information_schema, an
	// extension's), with their columns.
	Relations []Relation
	// contains filtered or unexported fields
}

Catalog is the loaded bootstrap catalog with lookup indexes.

func Load

func Load(major int) (*Catalog, error)

Load returns the embedded bootstrap catalog of a PostgreSQL major version. Parsing happens once per process per version.

func (*Catalog) AggregateByFn

func (c *Catalog) AggregateByFn(fn OID) *Aggregate

AggregateByFn returns the pg_aggregate row for an aggregate function oid, or nil.

func (*Catalog) CastBetween

func (c *Catalog) CastBetween(source, target OID) *Cast

CastBetween returns the pg_cast entry from source to target, or nil if none is declared. Callers must also handle the implicit cases pg_cast does not list (same type, domains, arrays, unknown).

func (*Catalog) FuncByOID

func (c *Catalog) FuncByOID(oid OID) *Func

FuncByOID returns the function with the given oid, or nil.

func (*Catalog) FuncsByName

func (c *Catalog) FuncsByName(name string) []*Func

FuncsByName returns all pg_catalog functions named name (overloads), in oid order.

func (*Catalog) OperatorByOID

func (c *Catalog) OperatorByOID(oid OID) *Operator

OperatorByOID returns the operator with the given oid, or nil.

func (*Catalog) OperatorsByName

func (c *Catalog) OperatorsByName(name string) []*Operator

OperatorsByName returns all pg_catalog operators with the given symbol (e.g. "="), in oid order.

func (*Catalog) RangeForSubtype

func (c *Catalog) RangeForSubtype(sub OID) *Range

RangeForSubtype returns the (first) range type over subtype, or nil.

func (*Catalog) RangeOf

func (c *Catalog) RangeOf(rng OID) *Range

RangeOf returns the pg_range entry of a range type, or nil.

func (*Catalog) RangeOfMulti

func (c *Catalog) RangeOfMulti(multi OID) *Range

RangeOfMulti returns the pg_range entry whose multirange type is multi, or nil.

func (*Catalog) RelationByName

func (c *Catalog) RelationByName(schema, name string) *Relation

RelationByName returns the system relation schema.name, or nil.

func (*Catalog) TypeByName

func (c *Catalog) TypeByName(name string) *Type

TypeByName returns the pg_catalog type with the given typname (e.g. "int4", "_text"), or nil.

func (*Catalog) TypeByOID

func (c *Catalog) TypeByOID(oid OID) *Type

TypeByOID returns the type with the given oid, or nil.

func (*Catalog) WithExtensions

func (c *Catalog) WithExtensions(names []string) (*Catalog, error)

WithExtensions returns a new catalog: this one plus the named extensions. An extension another requested one already bundles is not loaded twice. Objects are renumbered into a per-extension OID range; the namespace they were created in is kept (Type.Schema etc.).

type Extension

type Extension struct {
	Name     string
	Version  string
	Schema   string   // the namespace its objects were created in
	Requires []string // extensions the dump bundles
}

Extension describes one dumped extension.

func ReadExtension

func ReadExtension(major int, name string) (*Extension, error)

ReadExtension returns the metadata of a dumped extension for a PostgreSQL major version, or an error if there is no dump.

type Func

type Func struct {
	OID         OID
	Name        string
	Kind        byte // prokind: f function, a aggregate, w window, p procedure
	RetType     OID
	RetSet      bool
	Variadic    OID // element type of the variadic parameter, 0 if none
	NArgs       int16
	NArgDefault int16
	IsStrict    bool
	Volatile    byte     // i immutable, s stable, v volatile
	ArgTypes    []OID    // input args (proargtypes)
	AllArgTypes []OID    // all args incl. OUT/TABLE, nil when same as ArgTypes
	ArgModes    []byte   // i in, o out, b inout, v variadic, t table; nil when all in
	ArgNames    []string // nil when unnamed
	// Schema is the namespace of an extension's function; "" for pg_catalog.
	Schema string
}

Func is a row of pg_proc.

type OID

type OID uint32

OID is a PostgreSQL object identifier.

const (
	Bool                    OID = 16
	Bytea                   OID = 17
	Char                    OID = 18
	Name                    OID = 19
	Int8                    OID = 20
	Int2                    OID = 21
	Int4                    OID = 23
	Text                    OID = 25
	OIDType                 OID = 26
	RegProc                 OID = 24
	Tid                     OID = 27
	Aclitem                 OID = 1033
	MacAddr8                OID = 774
	Money                   OID = 790
	RegProcedure            OID = 2202
	RegOper                 OID = 2203
	RegOperator             OID = 2204
	RegClass                OID = 2205
	RegType                 OID = 2206
	RegRole                 OID = 4096
	RegNamespace            OID = 4089
	RegCollation            OID = 4191
	TxidSnapshot            OID = 2970
	PgSnapshot              OID = 5038
	Xid8                    OID = 5069
	Xid                     OID = 28
	Cid                     OID = 29
	JSON                    OID = 114
	XML                     OID = 142
	Float4                  OID = 700
	Float8                  OID = 701
	Unknown                 OID = 705
	BPChar                  OID = 1042
	Varchar                 OID = 1043
	Date                    OID = 1082
	Time                    OID = 1083
	Timestamp               OID = 1114
	TimestampTZ             OID = 1184
	Interval                OID = 1186
	TimeTZ                  OID = 1266
	Numeric                 OID = 1700
	Record                  OID = 2249
	Cstring                 OID = 2275
	Any                     OID = 2276
	AnyArray                OID = 2277
	Void                    OID = 2278
	Trigger                 OID = 2279
	AnyElement              OID = 2283
	AnyNonArray             OID = 2776
	AnyEnum                 OID = 3500
	UUID                    OID = 2950
	JSONB                   OID = 3802
	JSONPath                OID = 4072
	TSVector                OID = 3614
	AnyRange                OID = 3831
	AnyCompatible           OID = 5077
	AnyCompatibleArray      OID = 5078
	AnyCompatibleNonArray   OID = 5079
	AnyCompatibleRange      OID = 5080
	AnyMultirange           OID = 4537
	AnyCompatibleMultirange OID = 4538
)

Well-known type OIDs (pg_type.h). Only the ones the analyzer needs by name.

const (
	OIDVector  OID = 30
	Int2Vector OID = 22
)

Well-known OIDs of the vector types PG never coerces arrays into (find_coercion_pathway).

const FirstNormalObjectID OID = 16384

FirstNormalObjectID is where PG starts handing out OIDs for user objects.

type Operator

type Operator struct {
	OID      OID
	Name     string
	Kind     byte // b binary, l prefix
	Left     OID  // 0 for prefix operators
	Right    OID
	Result   OID
	Code     OID // implementing pg_proc oid
	Com      OID
	Negate   OID
	CanMerge bool
	CanHash  bool
	// Schema is the namespace of an extension's operator; "" for pg_catalog.
	Schema string
}

Operator is a row of pg_operator.

type Range

type Range struct {
	OID     OID
	Subtype OID
	Multi   OID
}

Range is a range type with its subtype and multirange type (pg_range).

type RelColumn

type RelColumn struct {
	Name    string
	Type    OID
	Typmod  int32
	NotNull bool
}

RelColumn is one attribute of a system relation.

type Relation

type Relation struct {
	OID     OID
	Name    string
	Kind    byte // relkind: r table, v view
	Schema  string
	Columns []RelColumn
}

Relation is a system table or view (pg_class + pg_attribute) the analyzer can resolve like a user table: pg_catalog's, information_schema's, or an extension's.

type Type

type Type struct {
	OID         OID
	Name        string
	Kind        byte // typtype: b base, c composite, d domain, e enum, p pseudo, r range, m multirange
	Category    byte // typcategory (§10.1 categories: N numeric, S string, D datetime, ...)
	IsPreferred bool
	Len         int16
	ByVal       bool
	Elem        OID // element type for arrays, 0 otherwise
	Array       OID // the array type over this type, 0 if none
	RelID       OID // composite: pg_class oid
	BaseType    OID // domain: underlying type
	Typmod      int32
	// Schema is the namespace of an extension's type ("public" usually); "" for pg_catalog.
	Schema string
}

Type is a row of pg_type.

func (*Type) IsArray

func (t *Type) IsArray() bool

IsArray reports whether t is a true array type: it has an element type and is a varlena (get_element_type). Fixed-length types with typelem (point, line, ...) are not.

func (*Type) IsPolymorphic

func (t *Type) IsPolymorphic() bool

IsPolymorphic reports whether t is one of the any* pseudo types (§38.2.5).

Directories

Path Synopsis
Command gen dumps the bootstrap catalog (pg_catalog objects) of the oracle's PostgreSQL into internal/catalog/data/<major>/*.tsv, and extension catalogs into internal/catalog/data/<major>/ext/<name>/.
Command gen dumps the bootstrap catalog (pg_catalog objects) of the oracle's PostgreSQL into internal/catalog/data/<major>/*.tsv, and extension catalogs into internal/catalog/data/<major>/ext/<name>/.

Jump to

Keyboard shortcuts

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