postgres

package
v0.0.0-...-a4119a3 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: AGPL-3.0 Imports: 9 Imported by: 1 module, 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.

Documentation

Index

Constants

View Source
const (
	MoneyOID        uint32 = 790
	TxidSnapshotOID uint32 = 2970
	TsvectorOID     uint32 = 3614
	TsqueryOID      uint32 = 3615
)

OID constants for types not covered by pgtype's built-in map.

Variables

This section is empty.

Functions

func BuildColumnSchemaMap

func BuildColumnSchemaMap(
	fields []pgconn.FieldDescription,
	typeMap *pgtype.Map,
	customTypeMapping map[uint32]CustomDataType,
) (map[string]ColumnSchema, error)

BuildColumnSchemaMap assembles a ColumnSchema map from pgx FieldDescriptions.

func CheckColumnExists

func CheckColumnExists(srcColName, dstColName string, dstColumns map[string]ColumnSchema, dstTableIdentifier string) error

CheckColumnExists returns an error if dstColName is not present in dstColumns.

func CheckColumnTypeCompatibility

func CheckColumnTypeCompatibility(
	srcColName, srcType string, srcTypeMod int32,
	dstColName, dstType string, dstTypeMod int32,
	dstTableIdentifier string,
) error

CheckColumnTypeCompatibility returns an error if the destination column type is not compatible with the source column type.

Compatibility rules (using pg_type.typname values, e.g. "int4", "varchar"):

  • Exact type match: always compatible, subject to typmod rules below.
  • varchar / bpchar → text: always compatible (text is a superset).
  • Integer promotion: destination may be a wider integer (int2 → int4 → int8).
  • varchar / bpchar same type: unbounded source into bounded destination is rejected; bounded source into narrower destination is rejected.
  • numeric same type: both sides constrained with different precision/scale → rejected; either side unbounded (typmod == -1) → compatible.

func CheckSchemaExists

func CheckSchemaExists(ctx context.Context, conn *pgx.Conn, schema string) error

CheckSchemaExists returns an error if the given schema does not exist in the database.

func CheckTableEmpty

func CheckTableEmpty(ctx context.Context, conn *pgx.Conn, tableIdentifier string) error

CheckTableEmpty returns an error if the given table already contains rows.

func CheckUnsupportedDatabase

func CheckUnsupportedDatabase(ctx context.Context, conn *pgx.Conn) error

func CheckWalLevel

func CheckWalLevel(ctx context.Context, conn *pgx.Conn) error

CheckWalLevel checks that the server's WAL level allows logical decoding. From PG19 a primary with wal_level=replica enables logical decoding on the first logical slot, and a standby can decode only once its primary has.

func ExtensionTablePrimaryKey

func ExtensionTablePrimaryKey(ctx context.Context, conn *pgx.Conn, table common.QualifiedTable) ([]string, error)

ExtensionTablePrimaryKey returns primary key columns when table belongs to an extension, nil otherwise. Extensions like postgis populate such tables (spatial_ref_sys) on CREATE EXTENSION

func GetCustomDataTypes

func GetCustomDataTypes(ctx context.Context, conn *pgx.Conn) (map[uint32]CustomDataType, error)

GetCustomDataTypes fetches all types from the PostgreSQL catalog. pg_catalog stays included: pgtype's map does not know every built-in (regclass, pg_lsn, oidvector, ...) and OIDToName falls back here.

func GetDestinationTableSchema

func GetDestinationTableSchema(
	ctx context.Context,
	conn *pgx.Conn,
	tableIdentifier string,
	customTypeMapping map[uint32]CustomDataType,
) (map[string]ColumnSchema, error)

GetDestinationTableSchema queries a PostgreSQL table's column type information using SELECT * FROM tableIdentifier LIMIT 0 to get field descriptions with OIDs. Returns pgx.ErrNoRows if the table exists but has no columns.

func IsYugabyteVersion

func IsYugabyteVersion(version string) bool

func OIDToName

func OIDToName(typeMap *pgtype.Map, oid uint32, customTypeMapping map[uint32]CustomDataType) (string, error)

OIDToName resolves a PostgreSQL type OID to its pg_type.typname string. It consults typeMap first, then falls back to a small set of well-known OIDs not covered by pgtype, and finally looks up customTypeMapping for enums/composites.

func ResolveDataType

func ResolveDataType(oid uint32, typmod int32, customTypeMapping map[uint32]CustomDataType) (uint32, int32)

ResolveDataType checks custom type mapping and resolves oid and typmod to its base type for a domain type

func ResolveDestinationColumnName

func ResolveDestinationColumnName(srcColName string, mappings []ColumnMapping) string

ResolveDestinationColumnName returns the destination column name for srcColName, applying the first matching rename from mappings. Falls back to srcColName if none match.

Types

type ColumnMapping

type ColumnMapping struct {
	SourceName      string
	DestinationName string
}

ColumnMapping holds a source→destination column name pair for rename resolution.

type ColumnSchema

type ColumnSchema struct {
	TypeName string
	TypeMod  int32
}

ColumnSchema holds the PostgreSQL type information for a single column, as returned by FieldDescriptions after a "SELECT * FROM table LIMIT 0" query.

type CustomDataType

type CustomDataType struct {
	Name  string
	Type  byte
	Delim byte // non-zero for array types

	// for domain types
	BaseOID    uint32
	BaseTypmod int32
}

CustomDataType holds metadata for a PostgreSQL custom type (enum, composite, domain, array).

Jump to

Keyboard shortcuts

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