pgtypes

package
v0.0.0-...-068cd59 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultTypeMap *pgtype.Map
View Source
var PostgresOIDToDuckDBTypeName = map[uint32]string{
	pgtype.BoolOID:        "BOOLEAN",
	pgtype.ByteaOID:       "BLOB",
	pgtype.QCharOID:       "UTINYINT",
	pgtype.Int2OID:        "SMALLINT",
	pgtype.Int4OID:        "INTEGER",
	pgtype.Int8OID:        "BIGINT",
	pgtype.Float4OID:      "FLOAT",
	pgtype.Float8OID:      "DOUBLE",
	pgtype.NumericOID:     "DECIMAL",
	pgtype.TextOID:        "VARCHAR",
	pgtype.VarcharOID:     "VARCHAR",
	pgtype.BPCharOID:      "VARCHAR",
	pgtype.NameOID:        "VARCHAR",
	pgtype.DateOID:        "DATE",
	pgtype.TimeOID:        "TIME",
	pgtype.TimetzOID:      "TIMETZ",
	pgtype.TimestampOID:   "TIMESTAMP",
	pgtype.TimestamptzOID: "TIMESTAMPTZ",
	pgtype.IntervalOID:    "INTERVAL",
	pgtype.UUIDOID:        "UUID",
	pgtype.BitOID:         "BIT",
	pgtype.VarbitOID:      "BIT",
	pgtype.JSONOID:        "JSON",
	pgtype.JSONBOID:       "JSON",
	pgtype.OIDOID:         "UINTEGER",
	pgtype.XIDOID:         "UINTEGER",
	pgtype.CIDOID:         "UINTEGER",
	pgtype.TIDOID:         "UBIGINT",

	pgtype.BoolArrayOID:        "BOOLEAN[]",
	pgtype.QCharArrayOID:       "TINYINT[]",
	pgtype.Int2ArrayOID:        "SMALLINT[]",
	pgtype.Int4ArrayOID:        "INTEGER[]",
	pgtype.Int8ArrayOID:        "BIGINT[]",
	pgtype.Float4ArrayOID:      "FLOAT[]",
	pgtype.Float8ArrayOID:      "DOUBLE[]",
	pgtype.NumericArrayOID:     "DECIMAL[]",
	pgtype.TextArrayOID:        "VARCHAR[]",
	pgtype.VarcharArrayOID:     "VARCHAR[]",
	pgtype.BPCharArrayOID:      "VARCHAR[]",
	pgtype.NameArrayOID:        "VARCHAR[]",
	pgtype.UUIDArrayOID:        "UUID[]",
	pgtype.DateArrayOID:        "DATE[]",
	pgtype.TimeArrayOID:        "TIME[]",
	pgtype.TimetzArrayOID:      "TIMETZ[]",
	pgtype.TimestampArrayOID:   "TIMESTAMP[]",
	pgtype.TimestamptzArrayOID: "TIMESTAMPTZ[]",
	pgtype.IntervalArrayOID:    "INTERVAL[]",
	pgtype.JSONArrayOID:        "JSON[]",
	pgtype.JSONBArrayOID:       "JSON[]",
	pgtype.BitArrayOID:         "BIT[]",
}

Functions

func DecodePrecisionScale

func DecodePrecisionScale(typmod int) (precision, scale int32, ok bool)

func GoDuckDBTypeNameToPostgresType

func GoDuckDBTypeNameToPostgresType(name string) (pt *pgtype.Type, precision, scale int32, fallback bool, err error)

GoDuckDBTypeNameToPostgresType parses a type name reported by the go-duckdb driver into a corresponding pgtype.Type with its precision and scale (if applicable). Unknown types are fallback to text.

TODO(fan): Make this function more rigorous for nested types.

func InferDriverSchema

func InferDriverSchema(rows driver.Rows) (sql.Schema, error)

func InferSchema

func InferSchema(rows *stdsql.Rows) (sql.Schema, error)

func PostgresTypeSize

func PostgresTypeSize(oid uint32) int32

func PostgresTypeToArrowType

func PostgresTypeToArrowType(p PostgresType) arrow.DataType

Types

type PostgresType

type PostgresType struct {
	PG        *pgtype.Type
	Precision int32
	Scale     int32
	// https://www.postgresql.org/docs/current/protocol-message-formats.html#PROTOCOL-MESSAGE-FORMATS-ROWDESCRIPTION
	Size int32
	// Fallback indicates that the type is not supported by the pgtype package and is approximated to the `text` fallback type.
	Fallback bool
}

func NewPostgresType

func NewPostgresType(registry *pgtype.Map, oid uint32, modifier int32) (PostgresType, error)

func (PostgresType) CollationCoercibility

func (p PostgresType) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte)

func (PostgresType) Compare

func (p PostgresType) Compare(v1 interface{}, v2 interface{}) (int, error)

func (PostgresType) Convert

func (p PostgresType) Convert(v interface{}) (interface{}, sql.ConvertInRange, error)

func (PostgresType) Encode

func (p PostgresType) Encode(v any, buf []byte) ([]byte, error)

func (PostgresType) Equals

func (p PostgresType) Equals(t sql.Type) bool

func (PostgresType) MaxTextResponseByteLength

func (p PostgresType) MaxTextResponseByteLength(_ *sql.Context) uint32

func (PostgresType) Promote

func (p PostgresType) Promote() sql.Type

func (PostgresType) SQL

func (p PostgresType) SQL(ctx *sql.Context, dest []byte, v interface{}) (sqltypes.Value, error)

func (PostgresType) String

func (p PostgresType) String() string

func (PostgresType) Type

func (p PostgresType) Type() query.Type

func (PostgresType) ValueType

func (p PostgresType) ValueType() reflect.Type

func (PostgresType) Zero

func (p PostgresType) Zero() interface{}

Jump to

Keyboard shortcuts

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