Documentation
¶
Index ¶
- Constants
- func BuildColumnSchemaMap(fields []pgconn.FieldDescription, typeMap *pgtype.Map, ...) (map[string]ColumnSchema, error)
- func CheckColumnExists(srcColName, dstColName string, dstColumns map[string]ColumnSchema, ...) error
- func CheckColumnTypeCompatibility(srcColName, srcType string, srcTypeMod int32, dstColName, dstType string, ...) error
- func CheckSchemaExists(ctx context.Context, conn *pgx.Conn, schema string) error
- func CheckTableEmpty(ctx context.Context, conn *pgx.Conn, tableIdentifier string) error
- func GetCustomDataTypes(ctx context.Context, conn *pgx.Conn) (map[uint32]CustomDataType, error)
- func GetDestinationTableSchema(ctx context.Context, conn *pgx.Conn, tableIdentifier string) (map[string]ColumnSchema, error)
- func OIDToName(typeMap *pgtype.Map, oid uint32, customTypeMapping map[uint32]CustomDataType) (string, error)
- func ParseNumericTypmod(typmod int32) (int16, int16)
- func ResolveDestinationColumnName(srcColName string, mappings []ColumnMapping) string
- type ColumnMapping
- type ColumnSchema
- type CustomDataType
Constants ¶
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 ¶
CheckSchemaExists returns an error if the given schema does not exist in the database.
func CheckTableEmpty ¶
CheckTableEmpty returns an error if the given table already contains rows.
func GetCustomDataTypes ¶
GetCustomDataTypes fetches all user-defined types from the PostgreSQL catalog.
func GetDestinationTableSchema ¶
func GetDestinationTableSchema(ctx context.Context, conn *pgx.Conn, tableIdentifier string) (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 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 ParseNumericTypmod ¶
This is to reverse what make_numeric_typmod of Postgres does: https://github.com/postgres/postgres/blob/21912e3c0262e2cfe64856e028799d6927862563/src/backend/utils/adt/numeric.c#L897
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 ¶
ColumnMapping holds a source→destination column name pair for rename resolution.
type ColumnSchema ¶
ColumnSchema holds the PostgreSQL type information for a single column, as returned by FieldDescriptions after a "SELECT * FROM table LIMIT 0" query.
type CustomDataType ¶
CustomDataType holds metadata for a PostgreSQL custom type (enum, composite, domain, array).