types

package
v0.0.0-...-1dc08c0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2021 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Oid is the type of a Postgres Object ID value.
	Oid = &T{InternalType: InternalType{
		Family: OidFamily, Oid: oid.T_oid, Locale: &emptyLocale}}

	// Regclass is the type of a Postgres regclass OID variant (T_regclass).
	RegClass = &T{InternalType: InternalType{
		Family: OidFamily, Oid: oid.T_regclass, Locale: &emptyLocale}}

	// RegNamespace is the type of a Postgres regnamespace OID variant
	// (T_regnamespace).
	RegNamespace = &T{InternalType: InternalType{
		Family: OidFamily, Oid: oid.T_regnamespace, Locale: &emptyLocale}}

	// RegProc is the type of a Postgres regproc OID variant (T_regproc).
	RegProc = &T{InternalType: InternalType{
		Family: OidFamily, Oid: oid.T_regproc, Locale: &emptyLocale}}

	// RegProcedure is the type of a Postgres regprocedure OID variant
	// (T_regprocedure).
	RegProcedure = &T{InternalType: InternalType{
		Family: OidFamily, Oid: oid.T_regprocedure, Locale: &emptyLocale}}

	// RegType is the type of of a Postgres regtype OID variant (T_regtype).
	RegType = &T{InternalType: InternalType{
		Family: OidFamily, Oid: oid.T_regtype, Locale: &emptyLocale}}

	// OidVector is a type-alias for an array of Oid values, but with a different
	// OID (T_oidvector instead of T__oid). It is a special VECTOR type used by
	// Postgres in system tables. OidVectors are 0-indexed, unlike normal arrays.
	OidVector = &T{InternalType: InternalType{
		Family: ArrayFamily, Oid: oid.T_oidvector, ArrayContents: Oid, Locale: &emptyLocale}}
)

Convenience list of pre-constructed OID-related types.

View Source
var (
	// Unknown is the type of an expression that statically evaluates to NULL.
	// This type should never be returned for an expression that does not *always*
	// evaluate to NULL.
	Unknown = &T{InternalType: InternalType{
		Family: UnknownFamily, Oid: oid.T_unknown, Locale: &emptyLocale}}

	// Bool is the type of a boolean true/false value.
	Bool = &T{InternalType: InternalType{
		Family: BoolFamily, Oid: oid.T_bool, Locale: &emptyLocale}}

	// VarBit is the type of an ordered list of bits (0 or 1 valued), with no
	// specified limit on the count of bits.
	VarBit = &T{InternalType: InternalType{
		Family: BitFamily, Oid: oid.T_varbit, Locale: &emptyLocale}}

	// Int is the type of a 64-bit signed integer. This is the canonical type
	// for IntFamily.
	Int = &T{InternalType: InternalType{
		Family: IntFamily, Width: 64, Oid: oid.T_int8, Locale: &emptyLocale}}

	// Int4 is the type of a 32-bit signed integer.
	Int4 = &T{InternalType: InternalType{
		Family: IntFamily, Width: 32, Oid: oid.T_int4, Locale: &emptyLocale}}

	// Int2 is the type of a 16-bit signed integer.
	Int2 = &T{InternalType: InternalType{
		Family: IntFamily, Width: 16, Oid: oid.T_int2, Locale: &emptyLocale}}

	// Float is the type of a 64-bit base-2 floating-point number (IEEE 754).
	// This is the canonical type for FloatFamily.
	Float = &T{InternalType: InternalType{
		Family: FloatFamily, Width: 64, Oid: oid.T_float8, Locale: &emptyLocale}}

	// Float4 is the type of a 32-bit base-2 floating-point number (IEEE 754).
	Float4 = &T{InternalType: InternalType{
		Family: FloatFamily, Width: 32, Oid: oid.T_float4, Locale: &emptyLocale}}

	// Decimal is the type of a base-10 floating-point number, with no specified
	// limit on precision (number of digits) or scale (digits to right of decimal
	// point).
	Decimal = &T{InternalType: InternalType{
		Family: DecimalFamily, Oid: oid.T_numeric, Locale: &emptyLocale}}

	// String is the type of a Unicode string, with no specified limit on the
	// count of characters. This is the canonical type for StringFamily. It is
	// reported as STRING in SHOW CREATE but "text" in introspection for
	// compatibility with PostgreSQL.
	String = &T{InternalType: InternalType{
		Family: StringFamily, Oid: oid.T_text, Locale: &emptyLocale}}

	// VarChar is equivalent to String, but has a differing OID (T_varchar),
	// which makes it show up differently when displayed. It is reported as
	// VARCHAR in SHOW CREATE and "character varying" in introspection for
	// compatibility with PostgreSQL.
	VarChar = &T{InternalType: InternalType{
		Family: StringFamily, Oid: oid.T_varchar, Locale: &emptyLocale}}

	// Name is a type-alias for String with a different OID (T_name). It is
	// reported as NAME in SHOW CREATE and "name" in introspection for
	// compatibility with PostgreSQL.
	Name = &T{InternalType: InternalType{
		Family: StringFamily, Oid: oid.T_name, Locale: &emptyLocale}}

	// Bytes is the type of a list of raw byte values.
	Bytes = &T{InternalType: InternalType{
		Family: BytesFamily, Oid: oid.T_bytea, Locale: &emptyLocale}}

	// Date is the type of a value specifying year, month, day (with no time
	// component). There is no timezone associated with it. For example:
	//
	//   YYYY-MM-DD
	//
	Date = &T{InternalType: InternalType{
		Family: DateFamily, Oid: oid.T_date, Locale: &emptyLocale}}

	// Time is the type of a value specifying hour, minute, second (with no date
	// component). By default, it has microsecond precision. There is no timezone
	// associated with it. For example:
	//
	//   HH:MM:SS.ssssss
	//
	Time = &T{InternalType: InternalType{
		Family:             TimeFamily,
		Precision:          0,
		TimePrecisionIsSet: false,
		Oid:                oid.T_time,
		Locale:             &emptyLocale,
	}}

	// TimeTZ is the type specifying hour, minute, second and timezone with
	// no date component. By default, it has microsecond precision.
	// For example:
	//
	//   HH:MM:SS.ssssss+-ZZ:ZZ
	TimeTZ = &T{InternalType: InternalType{
		Family:             TimeTZFamily,
		Precision:          0,
		TimePrecisionIsSet: false,
		Oid:                oid.T_timetz,
		Locale:             &emptyLocale,
	}}

	// Timestamp is the type of a value specifying year, month, day, hour, minute,
	// and second, but with no associated timezone. By default, it has microsecond
	// precision. For example:
	//
	//   YYYY-MM-DD HH:MM:SS.ssssss
	//
	Timestamp = &T{InternalType: InternalType{
		Family:             TimestampFamily,
		Precision:          0,
		TimePrecisionIsSet: false,
		Oid:                oid.T_timestamp,
		Locale:             &emptyLocale,
	}}

	// TimestampTZ is the type of a value specifying year, month, day, hour,
	// minute, and second, as well as an associated timezone. By default, it has
	// microsecond precision. For example:
	//
	//   YYYY-MM-DD HH:MM:SS.ssssss+-ZZ:ZZ
	//
	TimestampTZ = &T{InternalType: InternalType{
		Family:             TimestampTZFamily,
		Precision:          0,
		TimePrecisionIsSet: false,
		Oid:                oid.T_timestamptz,
		Locale:             &emptyLocale,
	}}

	// Interval is the type of a value describing a duration of time. By default,
	// it has microsecond precision.
	Interval = &T{InternalType: InternalType{
		Family:                IntervalFamily,
		Precision:             0,
		TimePrecisionIsSet:    false,
		Oid:                   oid.T_interval,
		Locale:                &emptyLocale,
		IntervalDurationField: &IntervalDurationField{},
	}}

	// Jsonb is the type of a JavaScript Object Notation (JSON) value that is
	// stored in a decomposed binary format (hence the "b" in jsonb).
	Jsonb = &T{InternalType: InternalType{
		Family: JsonFamily, Oid: oid.T_jsonb, Locale: &emptyLocale}}

	// Uuid is the type of a universally unique identifier (UUID), which is a
	// 128-bit quantity that is very unlikely to ever be generated again, and so
	// can be relied on to be distinct from all other UUID values.
	Uuid = &T{InternalType: InternalType{
		Family: UuidFamily, Oid: oid.T_uuid, Locale: &emptyLocale}}

	// INet is the type of an IPv4 or IPv6 network address. For example:
	//
	//   192.168.100.128/25
	//   FE80:CD00:0:CDE:1257:0:211E:729C
	//
	INet = &T{InternalType: InternalType{
		Family: INetFamily, Oid: oid.T_inet, Locale: &emptyLocale}}

	// Geometry is the type of a geospatial Geometry object.
	Geometry = &T{
		InternalType: InternalType{
			Family:      GeometryFamily,
			Oid:         oidext.T_geometry,
			Locale:      &emptyLocale,
			GeoMetadata: &GeoMetadata{},
		},
	}

	// Geography is the type of a geospatial Geography object.
	Geography = &T{
		InternalType: InternalType{
			Family:      GeographyFamily,
			Oid:         oidext.T_geography,
			Locale:      &emptyLocale,
			GeoMetadata: &GeoMetadata{},
		},
	}

	// Scalar contains all types that meet this criteria:
	//
	//   1. Scalar type (no ArrayFamily or TupleFamily types).
	//   2. Non-ambiguous type (no UnknownFamily or AnyFamily types).
	//   3. Canonical type for one of the type families.
	//
	Scalar = []*T{
		Bool,
		Int,
		Float,
		Decimal,
		Date,
		Timestamp,
		Interval,
		Geography,
		Geometry,
		String,
		Bytes,
		TimestampTZ,
		Oid,
		Uuid,
		INet,
		Time,
		TimeTZ,
		Jsonb,
		VarBit,
	}

	// Any is a special type used only during static analysis as a wildcard type
	// that matches any other type, including scalar, array, and tuple types.
	// Execution-time values should never have this type. As an example of its
	// use, many SQL builtin functions allow an input value to be of any type,
	// and so use this type in their static definitions.
	Any = &T{InternalType: InternalType{
		Family: AnyFamily, Oid: oid.T_anyelement, Locale: &emptyLocale}}

	// AnyArray is a special type used only during static analysis as a wildcard
	// type that matches an array having elements of any (uniform) type (including
	// nested array types). Execution-time values should never have this type.
	AnyArray = &T{InternalType: InternalType{
		Family: ArrayFamily, ArrayContents: Any, Oid: oid.T_anyarray, Locale: &emptyLocale}}

	// AnyEnum is a special type only used during static analysis as a wildcard
	// type that matches an possible enum value. Execution-time values should
	// never have this type.
	AnyEnum = &T{InternalType: InternalType{
		Family: EnumFamily, Locale: &emptyLocale, Oid: oid.T_anyenum}}

	// AnyTuple is a special type used only during static analysis as a wildcard
	// type that matches a tuple with any number of fields of any type (including
	// tuple types). Execution-time values should never have this type.
	AnyTuple = &T{InternalType: InternalType{
		Family: TupleFamily, TupleContents: []*T{Any}, Oid: oid.T_record, Locale: &emptyLocale}}

	// AnyCollatedString is a special type used only during static analysis as a
	// wildcard type that matches a collated string with any locale. Execution-
	// time values should never have this type.
	AnyCollatedString = &T{InternalType: InternalType{
		Family: CollatedStringFamily, Oid: oid.T_text, Locale: &emptyLocale}}

	// EmptyTuple is the tuple type with no fields. Note that this is different
	// than AnyTuple, which is a wildcard type.
	EmptyTuple = &T{InternalType: InternalType{
		Family: TupleFamily, Oid: oid.T_record, Locale: &emptyLocale}}

	// StringArray is the type of an array value having String-typed elements.
	StringArray = &T{InternalType: InternalType{
		Family: ArrayFamily, ArrayContents: String, Oid: oid.T__text, Locale: &emptyLocale}}

	// IntArray is the type of an array value having Int-typed elements.
	IntArray = &T{InternalType: InternalType{
		Family: ArrayFamily, ArrayContents: Int, Oid: oid.T__int8, Locale: &emptyLocale}}

	// FloatArray is the type of an array value having Float-typed elements.
	FloatArray = &T{InternalType: InternalType{
		Family: ArrayFamily, ArrayContents: Float, Oid: oid.T__float8, Locale: &emptyLocale}}

	// DecimalArray is the type of an array value having Decimal-typed elements.
	DecimalArray = &T{InternalType: InternalType{
		Family: ArrayFamily, ArrayContents: Decimal, Oid: oid.T__numeric, Locale: &emptyLocale}}

	// Int2Vector is a type-alias for an array of Int2 values with a different
	// OID (T_int2vector instead of T__int2). It is a special VECTOR type used
	// by Postgres in system tables. Int2vectors are 0-indexed, unlike normal arrays.
	Int2Vector = &T{InternalType: InternalType{
		Family: ArrayFamily, Oid: oid.T_int2vector, ArrayContents: Int2, Locale: &emptyLocale}}
)

Convenience list of pre-constructed types. Caller code can use any of these types, or use the MakeXXX methods to construct a custom type that is not listed here (e.g. if a custom width is needed).

View Source
var (
	Serial2Type = *Int2
	Serial4Type = *Int4
	Serial8Type = *Int
)

The SERIAL types are pseudo-types that are only used during parsing. After that, they should behave identically to INT columns. They are declared as INT types, but using different instances than types.Int, types.Int2, etc. so that they can be compared by pointer to differentiate them from the singleton INT types. While the usual requirement is that == is never used to compare types, this is one case where it's allowed.

View Source
var (
	ErrInvalidLengthTypes = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowTypes   = fmt.Errorf("proto: integer overflow")
)
View Source
var ArrayOids = map[oid.Oid]struct{}{}

ArrayOids is a set of all oids which correspond to an array type.

View Source
var (
	// DefaultIntervalTypeMetadata returns a duration field that is unset,
	// using INTERVAL or INTERVAL ( iconst32 ) syntax instead of INTERVAL
	// with a qualifier afterwards.
	DefaultIntervalTypeMetadata = IntervalTypeMetadata{}
)
View Source
var Family_name = map[int32]string{
	0:   "BoolFamily",
	1:   "IntFamily",
	2:   "FloatFamily",
	3:   "DecimalFamily",
	4:   "DateFamily",
	5:   "TimestampFamily",
	6:   "IntervalFamily",
	7:   "StringFamily",
	8:   "BytesFamily",
	9:   "TimestampTZFamily",
	10:  "CollatedStringFamily",
	12:  "OidFamily",
	13:  "UnknownFamily",
	14:  "UuidFamily",
	15:  "ArrayFamily",
	16:  "INetFamily",
	17:  "TimeFamily",
	18:  "JsonFamily",
	19:  "TimeTZFamily",
	20:  "TupleFamily",
	21:  "BitFamily",
	22:  "GeometryFamily",
	23:  "GeographyFamily",
	24:  "EnumFamily",
	100: "AnyFamily",
}
View Source
var Family_value = map[string]int32{
	"BoolFamily":           0,
	"IntFamily":            1,
	"FloatFamily":          2,
	"DecimalFamily":        3,
	"DateFamily":           4,
	"TimestampFamily":      5,
	"IntervalFamily":       6,
	"StringFamily":         7,
	"BytesFamily":          8,
	"TimestampTZFamily":    9,
	"CollatedStringFamily": 10,
	"OidFamily":            12,
	"UnknownFamily":        13,
	"UuidFamily":           14,
	"ArrayFamily":          15,
	"INetFamily":           16,
	"TimeFamily":           17,
	"JsonFamily":           18,
	"TimeTZFamily":         19,
	"TupleFamily":          20,
	"BitFamily":            21,
	"GeometryFamily":       22,
	"GeographyFamily":      23,
	"EnumFamily":           24,
	"AnyFamily":            100,
}
View Source
var IntervalDurationType_name = map[int32]string{
	0: "UNSET",
	1: "YEAR",
	2: "MONTH",
	3: "DAY",
	4: "HOUR",
	5: "MINUTE",
	6: "SECOND",
	7: "MILLISECOND",
}
View Source
var IntervalDurationType_value = map[string]int32{
	"UNSET":       0,
	"YEAR":        1,
	"MONTH":       2,
	"DAY":         3,
	"HOUR":        4,
	"MINUTE":      5,
	"SECOND":      6,
	"MILLISECOND": 7,
}

OidToType maps Postgres object IDs to CockroachDB types. We export the map instead of a method so that other packages can iterate over the map directly. Note that additional elements for the array Oid types are added in init().

Functions

func CheckArrayElementType

func CheckArrayElementType(t *T) error

CheckArrayElementType ensures that the given type can be used as the element type of an ArrayFamily-typed column. If not, it returns an error.

func IsAdditiveType

func IsAdditiveType(t *T) bool

IsAdditiveType returns true if the given type supports addition and subtraction.

func IsDateTimeType

func IsDateTimeType(t *T) bool

IsDateTimeType returns true if the given type is a date or time-related type.

func IsSerialType

func IsSerialType(typ *T) bool

IsSerialType returns whether or not the input type is a SERIAL type. This function should only be used during parsing.

func IsStringType

func IsStringType(t *T) bool

IsStringType returns true iff the given type is String or a collated string type.

func IsValidArrayElementType

func IsValidArrayElementType(t *T) (valid bool, issueNum int)

IsValidArrayElementType returns true if the given type can be used as the element type of an ArrayFamily-typed column. If the valid return is false, the issue number should be included in the error report to inform the user.

func IsWildcardTupleType

func IsWildcardTupleType(t *T) bool

IsWildcardTupleType returns true if this is the wildcard AnyTuple type. The wildcard type matches a tuple type having any number of fields (including 0).

func StableTypeIDToOID

func StableTypeIDToOID(id uint32) oid.Oid

StableTypeIDToOID converts a stable descriptor ID into a type OID.

func UserDefinedTypeOIDToID

func UserDefinedTypeOIDToID(oid oid.Oid) uint32

UserDefinedTypeOIDToID converts a user defined type OID into a stable descriptor ID.

Types

type EnumMetadata

type EnumMetadata struct {
	// PhysicalRepresentations is a slice of the byte array
	// physical representations of enum members.
	PhysicalRepresentations [][]byte
	// LogicalRepresentations is a slice of the string logical
	// representations of enum members.
	LogicalRepresentations []string
}

EnumMetadata is metadata about an ENUM needed for evaluation.

type Family

type Family int32

See the comment header for the T.Family method for more details.

const (
	// BoolFamily is the family of boolean true/false types.
	//
	//   Canonical: types.Bool
	//   Oid      : T_bool
	//
	// Examples:
	//   BOOL
	//
	BoolFamily Family = 0
	// IntFamily is the family of signed integer types.
	//
	//   Canonical: types.Int
	//   Oid      : T_int8, T_int4, T_int2
	//   Width    : 64, 32, 16
	//
	// Examples:
	//   INT
	//   INT8
	//   INT4
	//
	IntFamily Family = 1
	// FloatFamily is the family of base-2 floating-point types (IEEE 754).
	//
	//   Canonical: types.Float
	//   Oid      : T_float8, T_float4
	//   Width    : 64, 32
	//
	// Examples:
	//   FLOAT8
	//   FLOAT4
	//
	FloatFamily Family = 2
	// DecimalFamily is the family of base-10 floating and fixed point types.
	//
	//   Canonical    : types.Decimal
	//   Oid          : T_numeric
	//   Precision    : max # decimal digits (0 = no specified limit)
	//   Width (Scale): # digits after decimal point (0 = no specified limit)
	//
	// Examples:
	//   DECIMAL
	//   DECIMAL(10)
	//   DECIMAL(10,3)
	//
	DecimalFamily Family = 3
	// DateFamily is the family of date types that store only year/month/day with
	// no time component.
	//
	//   Canonical: types.Date
	//   Oid      : T_date
	//
	// Examples:
	//   DATE
	//
	DateFamily Family = 4
	// TimestampFamily is the family of date types that store a year/month/day
	// date component, as well as an hour/minute/second time component. There is
	// no timezone component (see TIMESTAMPTZ). Seconds can have varying precision
	// (defaults to microsecond precision). Currently, only microsecond precision
	// is supported.
	//
	//   Canonical: types.Timestamp
	//   Oid      : T_timestamp
	//   Precision: fractional seconds (3 = ms, 0,6 = us, 9 = ns, etc.)
	//
	// Examples:
	//   TIMESTAMP
	//   TIMESTAMP(6)
	//
	TimestampFamily Family = 5
	// IntervalFamily is the family of types describing a duration of time.
	// Currently, only microsecond precision is supported.
	//
	//   Canonical: types.Interval
	//   Oid      : T_interval
	//
	// Examples:
	//   INTERVAL
	//
	IntervalFamily Family = 6
	// StringFamily is the family of types containing Unicode textual strings.
	// This family includes types constructed by STRING, VARCHAR, CHAR, and "char"
	// column type definitions (CHAR and "char" are distinct PG types). Note
	// that while STRING and VARCHAR have no default width limit, CHAR has a
	// default width of 1.
	// TODO(andyk): "char" should have default width of 1 as well, but doesn't.
	//
	//   Canonical: types.String
	//   Oid      : T_text, T_varchar, T_bpchar, T_char
	//   Width    : max # characters (0 = no specified limit)
	//
	// Examples:
	//   STRING
	//   TEXT
	//   VARCHAR(10)
	//   CHAR
	//
	StringFamily Family = 7
	// BytesFamily is the family of types containing a list of raw byte values.
	//
	//   Canonical: types.BYTES
	//   Oid      : T_bytea
	//
	// Examples:
	//   BYTES
	//
	BytesFamily Family = 8
	// TimestampTZFamily is the family of date types that store a year/month/day
	// date component, as well as an hour/minute/second time component, along with
	// a timezone. Seconds can have varying precision (defaults to microsecond
	// precision). Currently, only microsecond precision is supported.
	//
	//   Canonical: types.TimestampTZ
	//   Oid      : T_timestamptz
	//   Precision: fractional seconds (3 = ms, 0,6 = us, 9 = ns, etc.)
	//
	// Examples:
	//   TIMESTAMPTZ
	//   TIMESTAMPTZ(6)
	//
	TimestampTZFamily Family = 9
	// CollatedStringFamily is the family of types containing Unicode textual
	// strings with an associated COLLATE value that specifies the locale used
	// for various character-based operations such as sorting, pattern matching,
	// and builtin functions like lower and upper.
	//
	//   Oid      : T_text, T_varchar, T_bpchar, T_char
	//   Width    : max # characters (0 = no specified limit)
	//   Locale   : name of locale (e.g. EN or DE)
	//
	// Examples:
	//   STRING COLLATE en
	//   VARCHAR(10) COLLATE de
	//
	CollatedStringFamily Family = 10
	// OidFamily is the family of types containing Postgres Object ID (Oid)
	// values. Oids are integer values that identify some object in the database,
	// like a type, relation, or procedure.
	//
	//   Canonical: types.Oid
	//   Oid      : T_oid, T_regclass, T_regproc, T_regprocedure, T_regtype,
	//              T_regnamespace
	//
	// Examples:
	//   OID
	//   REGCLASS
	//   REGPROC
	//
	// TODO(andyk): Oids should be part of the IntFamily, since they are treated
	//              as equivalent to ints by PG.
	OidFamily Family = 12
	// UnknownFamily is a special type family that tags expressions that
	// statically evaluate to NULL. An UnknownFamily expression *must* be NULL.
	// But the inverse is not true, since other types allow NULL values as well.
	// UnknownFamily types are not supported as a table column type, but can be
	// transferred through DistSQL streams.
	//
	//   Canonical: types.Unknown
	//   Oid      : T_unknown
	//
	UnknownFamily Family = 13
	// UuidFamily is the family of types containing universally unique
	// identifiers. A UUID is a 128-bit quantity that is very unlikely to ever be
	// generated again, and so can be relied on to be distinct from all other UUID
	// values.
	//
	//   Canonical: types.Uuid
	//   Oid      : T_uuid
	//
	// Examples:
	//   UUID
	//
	UuidFamily Family = 14
	// ArrayFamily is a family of non-scalar types that contain an ordered list of
	// elements. The elements of an array must all share the same type. Elements
	// can have have any type, including ARRAY. However, while the types package
	// supports nested arrays, other parts of CRDB do not currently support them.
	// Also, the length of array dimension(s) are ignored by PG and CRDB (e.g.
	// an array of length 11 could be inserted into a column declared as INT[11]).
	//
	// Array OID values are special. Rather than having a single T_array OID,
	// Postgres defines a separate OID for each possible array element type.
	// Here are some examples:
	//
	//   T__int8: array of int8 values
	//   T__text: array of text values
	//
	// Notice that each array OID has double underscores to distinguish it from
	// the OID of the scalar type it contains.
	//
	//   Oid          : T__int, T__text, T__numeric, etc.
	//   ArrayContents: types.T of the array element type
	//
	// Examples:
	//   INT[]
	//   VARCHAR(10)[] COLLATE EN
	//   DECIMAL(10,1)[]
	//   TIMESTAMP[5]
	//
	ArrayFamily Family = 15
	// INetFamily is the family of types containing IPv4 or IPv6 network address
	// identifiers (e.g. 192.168.100.128/25 or FE80:CD00:0:CDE:1257:0:211E:729C).
	//
	//   Canonical: types.INet
	//   Oid      : T_inet
	//
	// Examples:
	//   INET
	//
	INetFamily Family = 16
	// TimeFamily is the family of date types that store only hour/minute/second
	// with no date component. There is no timezone component. Seconds can have
	// varying precision (defaults to microsecond precision). Currently, only
	// microsecond precision is supported.
	//
	//   Canonical: types.Time
	//   Oid      : T_time
	//   Precision: fractional seconds (3 = ms, 0,6 = us, 9 = ns, etc.)
	//
	// Examples:
	//   TIME
	//   TIME(6)
	//
	TimeFamily Family = 17
	// JsonFamily is the family of types containing JavaScript Object Notation
	// (JSON) values. Currently, CRDB only supports JSONB values, which are stored
	// in a decomposed binary format.
	//
	//   Canonical: types.Jsonb
	//   Oid      : T_jsonb
	//
	// Examples:
	//   JSON
	//   JSONB
	//
	JsonFamily Family = 18
	// TimeTZFamily is the family of date types that store only hour/minute/second
	// and timestamp components, with no date component. Seconds can have
	// varying precision (defaults to microsecond precision). Currently, only
	// microsecond precision is supported.
	//
	//   Canonical: types.TimeTZ
	//   Oid      : T_timetz
	//   Precision: fractional seconds (3 = ms, 0,6 = us, 9 = ns, etc.)
	//
	// Examples:
	//   TIMETZ
	//
	TimeTZFamily Family = 19
	// TupleFamily is a family of non-scalar structural types that describes the
	// fields of a row or record. The fields can be of any type, including nested
	// tuple and array types. Fields can also have optional labels. Currently,
	// CRDB does not support tuple types as column types, but it is possible to
	// construct tuples using the ROW function or tuple construction syntax.
	//
	//   Oid          : T_record
	//   TupleContents: []*types.T of each tuple field
	//   TupleLabels  : []string of each tuple label
	//
	// Examples:
	//   (1, 'foo')
	//   ((1, 'foo') AS num, str)
	//   ROW(1, 'foo')
	//   (ROW(1, 'foo') AS num, str)
	//
	TupleFamily Family = 20
	// BitFamily is the family of types containing ordered lists of bit values
	// (0 or 1). Note that while VARBIT has no default width limit, BIT has a
	// default width limit of 1.
	//
	//   Canonical: types.VarBit
	//   Oid      : T_varbit, T_bit
	//   Width    : max # of bits (0 = no specified limit)
	//
	// Examples:
	//   VARBIT
	//   VARBIT(10)
	//   BIT
	//   BIT(10)
	//
	BitFamily Family = 21
	// GeometryFamily is a family that supports the Geometry geospatial type,
	// which is compatible with PostGIS's Geometry implementation.
	//
	//   Canonical: types.Geometry
	//   Oid      : oidext.T_geometry
	//
	// Examples:
	//   GEOMETRY
	//   GEOMETRY(LINESTRING)
	//   GEOMETRY(LINESTRING, SRID)
	GeometryFamily Family = 22
	// GeographyFamily is a family that supports the Geography geospatial type,
	// which is compatible with PostGIS's Geography implementation.
	//
	//   Canonical: types.Geography
	//   Oid      : oidext.T_geography
	//
	// Examples:
	//   GEOGRAPHY
	//   GEOGRAPHY(LINESTRING)
	//   GEOGRAPHY(LINESTRING, SRID)
	GeographyFamily Family = 23
	// EnumFamily is a family that represents all ENUM types. ENUM types
	// have data about the ENUM defined in a TypeDescriptor. The ID of
	// the TypeDescriptor that backs this ENUM is stored in the StableTypeID
	// field. It does not have a canonical form.
	EnumFamily Family = 24
	// AnyFamily is a special type family used during static analysis as a
	// wildcard type that matches any other type, including scalar, array, and
	// tuple types. Execution-time values should never have this type. As an
	// example of its use, many SQL builtin functions allow an input value to be
	// of any type, and so use this type in their static definitions.
	//
	//   Canonical: types.Any
	//   Oid      : T_anyelement
	//
	AnyFamily Family = 100
)

func (Family) Enum

func (x Family) Enum() *Family

func (Family) EnumDescriptor

func (Family) EnumDescriptor() ([]byte, []int)

func (Family) Name

func (f Family) Name() string

Name returns a user-friendly word indicating the family type.

TODO(radu): investigate whether anything breaks if we use enumvalue_customname and use String() instead.

func (Family) String

func (x Family) String() string

func (*Family) UnmarshalJSON

func (x *Family) UnmarshalJSON(data []byte) error

type GeoMetadata

type GeoMetadata struct {
	SRID      github_com_cockroachdb_cockroach_pkg_geo_geopb.SRID `protobuf:"varint,1,opt,name=srid,casttype=github.com/ruiaylin/pgparser/types/geo/geopb.SRID" json:"srid"`
	ShapeType geopb.ShapeType                                     `protobuf:"varint,2,opt,name=shape_type,json=shapeType,enum=cockroach.geopb.ShapeType" json:"shape_type"`
}

GeoMetadata contains metadata associated with Geospatial data types.

func (*GeoMetadata) Descriptor

func (*GeoMetadata) Descriptor() ([]byte, []int)

func (*GeoMetadata) Marshal

func (m *GeoMetadata) Marshal() (dAtA []byte, err error)

func (*GeoMetadata) MarshalTo

func (m *GeoMetadata) MarshalTo(dAtA []byte) (int, error)

func (*GeoMetadata) ProtoMessage

func (*GeoMetadata) ProtoMessage()

func (*GeoMetadata) Reset

func (m *GeoMetadata) Reset()

func (*GeoMetadata) SQLString

func (m *GeoMetadata) SQLString() string

SQLString outputs the GeoMetadata in a SQL-compatible string.

func (*GeoMetadata) Size

func (m *GeoMetadata) Size() (n int)

func (*GeoMetadata) String

func (m *GeoMetadata) String() string

func (*GeoMetadata) Unmarshal

func (m *GeoMetadata) Unmarshal(dAtA []byte) error

func (*GeoMetadata) XXX_DiscardUnknown

func (m *GeoMetadata) XXX_DiscardUnknown()

func (*GeoMetadata) XXX_Marshal

func (m *GeoMetadata) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*GeoMetadata) XXX_Merge

func (m *GeoMetadata) XXX_Merge(src proto.Message)

func (*GeoMetadata) XXX_Size

func (m *GeoMetadata) XXX_Size() int

func (*GeoMetadata) XXX_Unmarshal

func (m *GeoMetadata) XXX_Unmarshal(b []byte) error

type InternalType

type InternalType struct {
	// Family specifies a group of types that are compatible with one another.
	// See the header for the T.Family method for more details.
	Family Family `protobuf:"varint,1,opt,name=family,enum=cockroach.sql.sem.types.Family" json:"family"`
	// Width is the size or scale of the type, such as number of bits or
	// characters. See the T.Width method for more details.
	Width int32 `protobuf:"varint,2,opt,name=width" json:"width"`
	// Precision is the accuracy of the data type. See the T.Precision method for
	// more details. This field was also by FLOAT pre-2.1 (this was incorrect.)
	Precision int32 `protobuf:"varint,3,opt,name=precision" json:"precision"`
	// ArrayDimensions is deprecated in 19.2, since it was never used. It
	// previously contained the length of each dimension in the array. A
	// dimension of -1 meant that no bound was specified for that dimension. If
	// arrayDimensions was nil, then the array had one unbounded dimension.
	ArrayDimensions []int32 `protobuf:"varint,4,rep,name=array_dimensions,json=arrayDimensions" json:"array_dimensions,omitempty"`
	// Locale identifies a specific geographical, political, or cultural region that
	// impacts various character-based operations such as sorting, pattern matching,
	// and builtin functions like lower and upper. See the T.Locale method for
	// more details.
	Locale *string `protobuf:"bytes,5,opt,name=locale" json:"locale,omitempty"`
	// VisibleType is deprecated in 19.2, since it is now superseded by the Oid
	// field. It previously contained an alias for any types where our internal
	// representation is different than the user specification. Examples are INT4,
	// FLOAT4, etc. Mostly for Postgres compatibility.
	VisibleType int32 `protobuf:"varint,6,opt,name=visible_type,json=visibleType" json:"visible_type"`
	// ArrayElemType is deprecated in 19.2, since it is now superseded by the
	// ArrayContents field. It previously contained the type family of array
	// elements. The other array fields (width/precision/locale/etc) were used
	// to store the other attributes of the array's element type.
	ArrayElemType *Family `` /* 132-byte string literal not displayed */
	// TupleContents returns a slice containing the type of each tuple field. This
	// is nil for non-TUPLE types.
	TupleContents []*T `protobuf:"bytes,8,rep,name=tuple_contents,json=tupleContents" json:"tuple_contents,omitempty"`
	// TupleLabels returns a slice containing the labels of each tuple field. This
	// is nil for non-TUPLE types, or if the TUPLE type does not specify labels.
	TupleLabels []string `protobuf:"bytes,9,rep,name=tuple_labels,json=tupleLabels" json:"tuple_labels,omitempty"`
	// Oid returns the type's Postgres Object ID. See the header for the T.Oid
	// method for more details. For user-defined types, the OID value is an
	// offset (oidext.CockroachPredefinedOIDMax) away from the stable_type_id
	// field. This makes it easy to retrieve a type descriptor by OID.
	Oid github_com_lib_pq_oid.Oid `protobuf:"varint,10,opt,name=oid,customtype=github.com/lib/pq/oid.Oid" json:"oid"`
	// ArrayContents returns the type of array elements. This is nil for non-ARRAY
	// types.
	ArrayContents *T `protobuf:"bytes,11,opt,name=array_contents,json=arrayContents" json:"array_contents,omitempty"`
	// TimePrecisionIsSet indicates whether the precision was explicitly set.
	// It is currently in use for the TIME-related families and INTERVALs
	// where a Precision of 0 indicated the default precision of 6
	// in versions pre-20.1.
	// The rules for Precision to use are as follows:
	//   * If Precision is > 0, then that is the precision.
	//   * If Precision is 0, it will default to 6 if TimePrecisionIsSet is false
	//    (for compatibility reasons).
	//   * Otherwise, Precision = 0 and TimePrecisionIsSet = true, so it is
	//     actually 0.
	TimePrecisionIsSet bool `protobuf:"varint,12,opt,name=time_precision_is_set,json=timePrecisionIsSet" json:"time_precision_is_set"`
	// IntervalDurationField is populated for intervals, representing extra
	// typmod or precision data that may be required.
	IntervalDurationField *IntervalDurationField `protobuf:"bytes,13,opt,name=interval_duration_field,json=intervalDurationField" json:"interval_duration_field,omitempty"`
	// GeoMetadata is populated for geospatial types.
	GeoMetadata *GeoMetadata `protobuf:"bytes,14,opt,name=geo_metadata,json=geoMetadata" json:"geo_metadata,omitempty"`
	// UDTMetadata is populated for user defined types.
	UDTMetadata *PersistentUserDefinedTypeMetadata `protobuf:"bytes,15,opt,name=udt_metadata,json=udtMetadata" json:"udt_metadata,omitempty"`
}

InternalType is the protobuf encoding for SQL types. It is always wrapped by a T struct, and should never be used directly by outside packages. See the comment header for the T struct for more details.

func (*InternalType) Descriptor

func (*InternalType) Descriptor() ([]byte, []int)

func (*InternalType) Identical

func (t *InternalType) Identical(other *InternalType) bool

Identical is the internal implementation for T.Identical. See that comment for details.

func (*InternalType) Marshal

func (m *InternalType) Marshal() (dAtA []byte, err error)

func (*InternalType) MarshalTo

func (m *InternalType) MarshalTo(dAtA []byte) (int, error)

func (*InternalType) ProtoMessage

func (*InternalType) ProtoMessage()

func (*InternalType) Reset

func (m *InternalType) Reset()

func (*InternalType) Size

func (m *InternalType) Size() (n int)

func (*InternalType) String

func (m *InternalType) String() string

func (*InternalType) Unmarshal

func (m *InternalType) Unmarshal(dAtA []byte) error

func (*InternalType) XXX_DiscardUnknown

func (m *InternalType) XXX_DiscardUnknown()

func (*InternalType) XXX_Marshal

func (m *InternalType) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*InternalType) XXX_Merge

func (m *InternalType) XXX_Merge(src proto.Message)

func (*InternalType) XXX_Size

func (m *InternalType) XXX_Size() int

func (*InternalType) XXX_Unmarshal

func (m *InternalType) XXX_Unmarshal(b []byte) error

type IntervalDurationField

type IntervalDurationField struct {
	// DurationType is the unit of measurement in which durations
	// should truncate themselves to.
	// This (unlike precision) gets truncated downward.
	DurationType IntervalDurationType `` /* 131-byte string literal not displayed */
	// FromDurationType is the left side of the "duration field".
	// i.e. in the `DurationType_1 TO DurationType_2` syntax, this represents `DurationType_1`.
	// Note this is ignored, see https://www.postgresql.org/message-id/20110510040219.GD5617%40tornado.gateway.2wire.net.
	FromDurationType IntervalDurationType `` /* 145-byte string literal not displayed */
}

IntervalDurationField represents precisions in intervals which are outside of the regular time precision syntax. i.e. instead of INTERVAL(6), we can have INTERVAL SECOND(6), INTERVAL MONTH, etc. This is represented as a bitmask on the first 4 bits of precision in postgres.

func (*IntervalDurationField) Descriptor

func (*IntervalDurationField) Descriptor() ([]byte, []int)

func (*IntervalDurationField) IsDayToHour

func (m *IntervalDurationField) IsDayToHour() bool

IsDayToHour returns whether the IntervalDurationField represents the DAY TO HOUR interval qualifier.

func (*IntervalDurationField) IsMinuteToSecond

func (m *IntervalDurationField) IsMinuteToSecond() bool

IsMinuteToSecond returns whether the IntervalDurationField represents the MINUTE TO SECOND interval qualifier.

func (*IntervalDurationField) Marshal

func (m *IntervalDurationField) Marshal() (dAtA []byte, err error)

func (*IntervalDurationField) MarshalTo

func (m *IntervalDurationField) MarshalTo(dAtA []byte) (int, error)

func (*IntervalDurationField) ProtoMessage

func (*IntervalDurationField) ProtoMessage()

func (*IntervalDurationField) Reset

func (m *IntervalDurationField) Reset()

func (*IntervalDurationField) Size

func (m *IntervalDurationField) Size() (n int)

func (*IntervalDurationField) String

func (m *IntervalDurationField) String() string

func (*IntervalDurationField) Unmarshal

func (m *IntervalDurationField) Unmarshal(dAtA []byte) error

func (*IntervalDurationField) XXX_DiscardUnknown

func (m *IntervalDurationField) XXX_DiscardUnknown()

func (*IntervalDurationField) XXX_Marshal

func (m *IntervalDurationField) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*IntervalDurationField) XXX_Merge

func (m *IntervalDurationField) XXX_Merge(src proto.Message)

func (*IntervalDurationField) XXX_Size

func (m *IntervalDurationField) XXX_Size() int

func (*IntervalDurationField) XXX_Unmarshal

func (m *IntervalDurationField) XXX_Unmarshal(b []byte) error

type IntervalDurationType

type IntervalDurationType int32

IntervalDurationType represents a duration that can be used when defining an Interval Duration Field. See https://www.postgresql.org/docs/current/datatype-datetime.html.

const (
	// UNSET defaults to SECOND during evaluation.
	// This indicates no typmod.
	IntervalDurationType_UNSET  IntervalDurationType = 0
	IntervalDurationType_YEAR   IntervalDurationType = 1
	IntervalDurationType_MONTH  IntervalDurationType = 2
	IntervalDurationType_DAY    IntervalDurationType = 3
	IntervalDurationType_HOUR   IntervalDurationType = 4
	IntervalDurationType_MINUTE IntervalDurationType = 5
	// SECOND is the only unit where precision can be added.
	IntervalDurationType_SECOND IntervalDurationType = 6
	// MILLISECOND is not technically part of the SQL standard for intervals, but we
	// provide it as a field to allow code to parse intervals with a default unit
	// of milliseconds, which is useful for some internal use cases like
	// statement_timeout.
	IntervalDurationType_MILLISECOND IntervalDurationType = 7
)

func (IntervalDurationType) Enum

func (IntervalDurationType) EnumDescriptor

func (IntervalDurationType) EnumDescriptor() ([]byte, []int)

func (IntervalDurationType) String

func (x IntervalDurationType) String() string

func (*IntervalDurationType) UnmarshalJSON

func (x *IntervalDurationType) UnmarshalJSON(data []byte) error

type IntervalTypeMetadata

type IntervalTypeMetadata struct {
	// DurationField represents the duration field definition.
	DurationField IntervalDurationField
	// Precision is the precision to use - note this matches InternalType rules.
	Precision int32
	// PrecisionIsSet indicates whether Precision is explicitly set.
	PrecisionIsSet bool
}

IntervalTypeMetadata is metadata pertinent for intervals.

type PersistentUserDefinedTypeMetadata

type PersistentUserDefinedTypeMetadata struct {
	// StableTypeID is the ID of the backing TypeDescriptor for this type.
	StableTypeID uint32 `protobuf:"varint,1,opt,name=stable_type_id,json=stableTypeId" json:"stable_type_id"`
	// StableArrayTypeID is the ID of the TypeDescriptor that defines the backs
	// the automatically generated array type for this type. StableArrayTypeID
	// is only set for user defined types that aren't arrays.
	StableArrayTypeID uint32 `protobuf:"varint,2,opt,name=stable_array_type_id,json=stableArrayTypeId" json:"stable_array_type_id"`
}

PersistentUserDefinedTypeMetadata contains user defined type metadata that will be serialized to disk, unlike other user defined type metadata that is only stored in memory once a type is resolved.

func (*PersistentUserDefinedTypeMetadata) Descriptor

func (*PersistentUserDefinedTypeMetadata) Descriptor() ([]byte, []int)

func (*PersistentUserDefinedTypeMetadata) Marshal

func (m *PersistentUserDefinedTypeMetadata) Marshal() (dAtA []byte, err error)

func (*PersistentUserDefinedTypeMetadata) MarshalTo

func (m *PersistentUserDefinedTypeMetadata) MarshalTo(dAtA []byte) (int, error)

func (*PersistentUserDefinedTypeMetadata) ProtoMessage

func (*PersistentUserDefinedTypeMetadata) ProtoMessage()

func (*PersistentUserDefinedTypeMetadata) Reset

func (*PersistentUserDefinedTypeMetadata) Size

func (m *PersistentUserDefinedTypeMetadata) Size() (n int)

func (*PersistentUserDefinedTypeMetadata) String

func (*PersistentUserDefinedTypeMetadata) Unmarshal

func (m *PersistentUserDefinedTypeMetadata) Unmarshal(dAtA []byte) error

func (*PersistentUserDefinedTypeMetadata) XXX_DiscardUnknown

func (m *PersistentUserDefinedTypeMetadata) XXX_DiscardUnknown()

func (*PersistentUserDefinedTypeMetadata) XXX_Marshal

func (m *PersistentUserDefinedTypeMetadata) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*PersistentUserDefinedTypeMetadata) XXX_Merge

func (*PersistentUserDefinedTypeMetadata) XXX_Size

func (m *PersistentUserDefinedTypeMetadata) XXX_Size() int

func (*PersistentUserDefinedTypeMetadata) XXX_Unmarshal

func (m *PersistentUserDefinedTypeMetadata) XXX_Unmarshal(b []byte) error

type T

type T struct {
	// InternalType should never be directly referenced outside this package. The
	// only reason it is exported is because gogoproto panics when printing the
	// string representation of an unexported field. This is a problem when this
	// struct is embedded in a larger struct (like a ColumnDescriptor).
	InternalType InternalType

	// Fields that are only populated when hydrating from a user defined
	// type descriptor. It is assumed that a user defined type is only used
	// once its metadata has been hydrated through the process of type resolution.
	TypeMeta UserDefinedTypeMetadata
}

T is an instance of a SQL scalar, array, or tuple type. It describes the domain of possible values which a column can return, or to which an expression can evaluate. The type system does not differentiate between nullable and non-nullable types. It is up to the caller to store that information separately if it is needed. Here are some example types:

INT4                     - any 32-bit integer
DECIMAL(10, 3)           - any base-10 value with at most 10 digits, with
                           up to 3 to right of decimal point
FLOAT[]                  - array of 64-bit IEEE 754 floating-point values
TUPLE[TIME, VARCHAR(20)] - any pair of values where first value is a time
                           of day and the second value is a string having
                           up to 20 characters

Fundamentally, a type consists of the following attributes, each of which has a corresponding accessor method. Some of these attributes are only defined for a subset of types. See the method comments for more details.

Family        - equivalence group of the type (enumeration)
Oid           - Postgres Object ID that describes the type (enumeration)
Precision     - maximum accuracy of the type (numeric)
Width         - maximum size or scale of the type (numeric)
Locale        - location which governs sorting, formatting, etc. (string)
ArrayContents - array element type (T)
TupleContents - slice of types of each tuple field ([]*T)
TupleLabels   - slice of labels of each tuple field ([]string)

Some types are not currently allowed as the type of a column (e.g. nested arrays). Other usages of the types package may have similar restrictions. Each such caller is responsible for enforcing their own restrictions; it's not the concern of the types package.

Implementation-wise, types.T wraps a protobuf-generated InternalType struct. The generated protobuf code defines the struct fields, marshals/unmarshals them, formats a string representation, etc. Meanwhile, the wrapper types.T struct overrides the Marshal/Unmarshal methods in order to map to/from older persisted InternalType representations. For example, older versions of InternalType (previously called ColumnType) used a VisibleType field to represent INT2, whereas newer versions use Width/Oid. Unmarshal upgrades from this old format to the new, and Marshal downgrades, thus preserving backwards compatibility.

Simple (unary) scalars types ----------------------------

| SQL type | Family | Oid | Precision | Width | |-------------------|----------------|---------------|-----------|-------| | NULL (unknown) | UNKNOWN | T_unknown | 0 | 0 | | BOOL | BOOL | T_bool | 0 | 0 | | DATE | DATE | T_date | 0 | 0 | | TIMESTAMP | TIMESTAMP | T_timestamp | 0 | 0 | | INTERVAL | INTERVAL | T_interval | 0 | 0 | | TIMESTAMPTZ | TIMESTAMPTZ | T_timestamptz | 0 | 0 | | OID | OID | T_oid | 0 | 0 | | UUID | UUID | T_uuid | 0 | 0 | | INET | INET | T_inet | 0 | 0 | | TIME | TIME | T_time | 0 | 0 | | TIMETZ | TIMETZ | T_timetz | 0 | 0 | | JSON | JSONB | T_jsonb | 0 | 0 | | JSONB | JSONB | T_jsonb | 0 | 0 | | | | | | | | BYTES | BYTES | T_bytea | 0 | 0 | | | | | | | | STRING | STRING | T_text | 0 | 0 | | STRING(N) | STRING | T_text | 0 | N | | VARCHAR | STRING | T_varchar | 0 | 0 | | VARCHAR(N) | STRING | T_varchar | 0 | N | | CHAR | STRING | T_bpchar | 0 | 1 | | CHAR(N) | STRING | T_bpchar | 0 | N | | "char" | STRING | T_char | 0 | 0 | | NAME | STRING | T_name | 0 | 0 | | | | | | | | STRING COLLATE en | COLLATEDSTRING | T_text | 0 | 0 | | STRING(N) COL... | COLLATEDSTRING | T_text | 0 | N | | VARCHAR COL... | COLLATEDSTRING | T_varchar | 0 | N | | VARCHAR(N) COL... | COLLATEDSTRING | T_varchar | 0 | N | | CHAR COL... | COLLATEDSTRING | T_bpchar | 0 | 1 | | CHAR(N) COL... | COLLATEDSTRING | T_bpchar | 0 | N | | "char" COL... | COLLATEDSTRING | T_char | 0 | 0 | | | | | | | | DECIMAL | DECIMAL | T_decimal | 0 | 0 | | DECIMAL(N) | DECIMAL | T_decimal | N | 0 | | DECIMAL(N,M) | DECIMAL | T_decimal | N | M | | | | | | | | FLOAT8 | FLOAT | T_float8 | 0 | 0 | | FLOAT4 | FLOAT | T_float4 | 0 | 0 | | | | | | | | BIT | BIT | T_bit | 0 | 1 | | BIT(N) | BIT | T_bit | 0 | N | | VARBIT | BIT | T_varbit | 0 | 0 | | VARBIT(N) | BIT | T_varbit | 0 | N | | | | | | | | INT,INTEGER | INT | T_int8 | 0 | 64 | | INT2,SMALLINT | INT | T_int2 | 0 | 16 | | INT4 | INT | T_int4 | 0 | 32 | | INT8,INT64,BIGINT | INT | T_int8 | 0 | 64 |

Tuple types -----------

These cannot (yet) be used in tables but are used in DistSQL flow processors for queries that have tuple-typed intermediate results.

| Field | Description | |-----------------|---------------------------------------------------------| | Family | TupleFamily | | Oid | T_record | | TupleContents | Contains tuple field types (can be recursively defined) | | TupleLabels | Contains labels for each tuple field |

Array types -----------

| Field | Description | |-----------------|---------------------------------------------------------| | Family | ArrayFamily | | Oid | T__XXX (double underscores), where XXX is the Oid name | | | of a scalar type | | ArrayContents | Type of array elements (scalar, array, or tuple) |

There are two special ARRAY types:

| SQL type | Family | Oid | ArrayContents | |-------------------|----------------|---------------|---------------| | INT2VECTOR | ARRAY | T_int2vector | Int | | OIDVECTOR | ARRAY | T_oidvector | Oid |

When these types are themselves made into arrays, the Oids become T__int2vector and T__oidvector, respectively.

User defined types ------------------

* Enums | Field | Description | |---------------|--------------------------------------------| | Family | EnumFamily | | Oid | A unique OID generated upon enum creation |

See types.proto for the corresponding proto definition. Its automatic type declaration is suppressed in the proto so that it is possible to add additional fields to T without serializing them.

func MakeArray

func MakeArray(typ *T) *T

MakeArray constructs a new instance of an ArrayFamily type with the given element type (which may itself be an ArrayFamily type).

func MakeBit

func MakeBit(width int32) *T

MakeBit constructs a new instance of the BIT type (oid = T_bit) having the given max # bits (0 = unspecified number).

func MakeChar

func MakeChar(width int32) *T

MakeChar constructs a new instance of the CHAR type (oid = T_bpchar) having the given max # characters (0 = unspecified number).

func MakeCollatedString

func MakeCollatedString(strType *T, locale string) *T

MakeCollatedString constructs a new instance of a CollatedStringFamily type that is collated according to the given locale. The new type is based upon the given string type, having the same oid and width values. For example:

STRING      => STRING COLLATE EN
VARCHAR(20) => VARCHAR(20) COLLATE EN

func MakeDecimal

func MakeDecimal(precision, scale int32) *T

MakeDecimal constructs a new instance of a DECIMAL type (oid = T_numeric) that has at most "precision" # of decimal digits (0 = unspecified number of digits) and at most "scale" # of decimal digits after the decimal point (0 = unspecified number of digits). scale must be <= precision.

func MakeEnum

func MakeEnum(typeID, arrayTypeID uint32) *T

MakeEnum constructs a new instance of an EnumFamily type with the given stable type ID. Note that it does not hydrate cached fields on the type.

func MakeGeography

func MakeGeography(shape geopb.ShapeType, srid geopb.SRID) *T

MakeGeography constructs a new instance of a geography-related type.

func MakeGeometry

func MakeGeometry(shape geopb.ShapeType, srid geopb.SRID) *T

MakeGeometry constructs a new instance of a GEOMETRY type (oid = T_geometry) that has the given shape and SRID.

func MakeInterval

func MakeInterval(itm IntervalTypeMetadata) *T

MakeInterval constructs a new instance of a INTERVAL type (oid = T_interval) with a duration field.

To use the default precision and field, use the `Interval` variable.

func MakeLabeledTuple

func MakeLabeledTuple(contents []*T, labels []string) *T

MakeLabeledTuple constructs a new instance of a TupleFamily type with the given field types and labels.

func MakeQChar

func MakeQChar(width int32) *T

MakeQChar constructs a new instance of the "char" type (oid = T_char) having the given max # characters (0 = unspecified number).

func MakeScalar

func MakeScalar(family Family, o oid.Oid, precision, width int32, locale string) *T

MakeScalar constructs a new instance of a scalar type (i.e. not array or tuple types) using the provided fields.

func MakeString

func MakeString(width int32) *T

MakeString constructs a new instance of the STRING type (oid = T_text) having the given max # characters (0 = unspecified number).

func MakeTime

func MakeTime(precision int32) *T

MakeTime constructs a new instance of a TIME type (oid = T_time) that has at most the given number of fractional second digits.

To use the default precision, use the `Time` variable.

func MakeTimeTZ

func MakeTimeTZ(precision int32) *T

MakeTimeTZ constructs a new instance of a TIMETZ type (oid = T_timetz) that has at most the given number of fractional second digits.

To use the default precision, use the `TimeTZ` variable.

func MakeTimestamp

func MakeTimestamp(precision int32) *T

MakeTimestamp constructs a new instance of a TIMESTAMP type that has at most the given number of fractional second digits.

To use the default precision, use the `Timestamp` variable.

func MakeTimestampTZ

func MakeTimestampTZ(precision int32) *T

MakeTimestampTZ constructs a new instance of a TIMESTAMPTZ type that has at most the given number of fractional second digits.

To use the default precision, use the `TimestampTZ` variable.

func MakeTuple

func MakeTuple(contents []*T) *T

MakeTuple constructs a new instance of a TupleFamily type with the given field types (some/all of which may be other TupleFamily types).

Warning: the contents slice is used directly; the caller should not modify it after calling this function.

func MakeVarBit

func MakeVarBit(width int32) *T

MakeVarBit constructs a new instance of the BIT type (oid = T_varbit) having the given max # bits (0 = unspecified number).

func MakeVarChar

func MakeVarChar(width int32) *T

MakeVarChar constructs a new instance of the VARCHAR type (oid = T_varchar) having the given max # characters (0 = unspecified number).

func TypeForNonKeywordTypeName

func TypeForNonKeywordTypeName(name string) (*T, bool, int)

TypeForNonKeywordTypeName returns the column type for the string name of a type, if one exists. The third return value indicates:

 0 if no error or the type is not known in postgres.
 -1 if the type is known in postgres.
>0 for a github issue number.

func (*T) ArrayContents

func (t *T) ArrayContents() *T

ArrayContents returns the type of array elements. This is nil for types that are not in the ArrayFamily.

func (*T) DebugString

func (t *T) DebugString() string

DebugString returns a detailed dump of the type protobuf struct, suitable for debugging scenarios.

func (*T) Descriptor

func (*T) Descriptor() ([]byte, []int)

func (*T) EnumGetIdxOfLogical

func (t *T) EnumGetIdxOfLogical(logical string) (int, error)

EnumGetIdxOfLogical returns the index within the TypeMeta's slice of enum logical representations that matches the input string.

func (*T) EnumGetIdxOfPhysical

func (t *T) EnumGetIdxOfPhysical(phys []byte) (int, error)

EnumGetIdxOfPhysical returns the index within the TypeMeta's slice of enum physical representations that matches the input byte slice.

func (*T) Equal

func (t *T) Equal(other *T) bool

Equal is for use in generated protocol buffer code only.

func (*T) Equivalent

func (t *T) Equivalent(other *T) bool

Equivalent returns true if this type is "equivalent" to the given type. Equivalent types are compatible with one another: they can be compared, assigned, and unioned. Equivalent types must always have the same type family for the root type and any descendant types (i.e. in case of array or tuple types). Types in the CollatedStringFamily must have the same locale. But other attributes of equivalent types, such as width, precision, and oid, can be different.

Wildcard types (e.g. Any, AnyArray, AnyTuple, etc) have special equivalence behavior. AnyFamily types match any other type, including other AnyFamily types. And a wildcard collation (empty string) matches any other collation.

func (*T) EquivalentOrNull

func (t *T) EquivalentOrNull(other *T) bool

EquivalentOrNull is the same as Equivalent, except it returns true if: * `t` is Unknown (i.e., NULL) and `other` is not a tuple, * `t` is a tuple with all non-Unknown elements matching the types in `other`.

func (*T) Family

func (t *T) Family() Family

Family specifies a group of types that are compatible with one another. Types in the same family can be compared, assigned, etc., but may differ from one another in width, precision, locale, and other attributes. For example, it is always an error to insert an INT value into a FLOAT column, because they are not in the same family. However, values of different types within the same family are "insert-compatible" with one another. Insertion may still result in an error because of width overflow or other constraints, but it can at least be attempted.

Families are convenient for performing type switches on types, because in most cases it is the type family that matters, not the specific type. For example, when CRDB encodes values, it maintains routines for each family, since types in the same family encode in very similar ways.

Most type families have an associated "canonical type" that is the default representative of that family, and which is a superset of all other types in that family. Values with other types (in the same family) can always be trivially converted to the canonical type with no loss of information. For example, the canonical type for IntFamily is Int, which is a 64-bit integer. Both 32-bit and 16-bit integers can be trivially converted to it.

Execution operators and functions are permissive in terms of input (allow any type within a given family), and typically return only values having canonical types as output. For example, the IntFamily Plus operator allows values having any IntFamily type as input. But then it will always convert those values to 64-bit integers, and return a final 64-bit integer value (types.Int). Doing this vastly reduces the required number of operator overloads.

func (*T) GeoMetadata

func (t *T) GeoMetadata() (*GeoMetadata, error)

GeoMetadata returns the GeoMetadata of the type object if it exists. This should only exist on Geometry and Geography types.

func (*T) GeoSRIDOrZero

func (t *T) GeoSRIDOrZero() geopb.SRID

GeoSRIDOrZero returns the geo SRID of the type object if it exists. This should only exist on a subset of Geometry and Geography types.

func (*T) Identical

func (t *T) Identical(other *T) bool

Identical returns true if every field in this ColumnType is exactly the same as every corresponding field in the given ColumnType. Identical performs a deep comparison, traversing any Tuple or Array contents.

NOTE: Consider whether the desired semantics really require identical types, or if Equivalent is the right method to call instead.

func (*T) InformationSchemaName

func (t *T) InformationSchemaName() string

InformationSchemaName returns the string suitable to populate the data_type column of information_schema.columns.

This is different from SQLString() in that it must report SQL standard names that are compatible with PostgreSQL client expectations.

func (*T) IntervalTypeMetadata

func (t *T) IntervalTypeMetadata() (IntervalTypeMetadata, error)

IntervalTypeMetadata returns the IntervalTypeMetadata for interval types.

func (*T) IsAmbiguous

func (t *T) IsAmbiguous() bool

IsAmbiguous returns true if this type is in UnknownFamily or AnyFamily. Instances of ambiguous types can be NULL or be in one of several different type families. This is important for parameterized types to determine whether they are fully concrete or not.

func (*T) Locale

func (t *T) Locale() string

Locale identifies a specific geographical, political, or cultural region that impacts various character-based operations such as sorting, pattern matching, and builtin functions like lower and upper. It is only defined for the types in the CollatedStringFamily, and is the empty string for all other types.

func (*T) Marshal

func (t *T) Marshal() (data []byte, err error)

Marshal serializes a type into a byte representation using gogo protobuf serialization rules. It returns the resulting bytes as a slice. The bytes are serialized in a format that is backwards-compatible with the previous version of CRDB so that clusters can run in mixed version mode during upgrade.

bytes, err := protoutil.Marshal(&typ)

func (*T) MarshalTo

func (t *T) MarshalTo(data []byte) (int, error)

MarshalTo behaves like Marshal, except that it deserializes to an existing byte slice and returns the number of bytes written to it. The slice must already have sufficient capacity. Callers can use the Size method to determine how much capacity needs to be allocated.

Marshal is part of the protoutil.Message interface.

func (*T) Name

func (t *T) Name() string

Name returns a single word description of the type that describes it succinctly, but without all the details, such as width, locale, etc. The name is sometimes the same as the name returned by SQLStandardName, but is more CRDB friendly.

TODO(andyk): Should these be changed to be the same as SQLStandardName?

func (*T) Oid

func (t *T) Oid() oid.Oid

Oid returns the type's Postgres Object ID. The OID identifies the type more specifically than the type family, and is used by the Postgres wire protocol various Postgres catalog tables, functions like pg_typeof, etc. Maintaining the OID is required for Postgres-compatibility.

func (*T) PGName

func (t *T) PGName() string

PGName returns the Postgres name for the type. This is sometimes different than the native CRDB name for it (i.e. the Name function). It is used when compatibility with PG is important. Examples of differences:

Name()       PGName()
--------------------------
char         bpchar
"char"       char
bytes        bytea
int4[]       _int4

func (*T) Precision

func (t *T) Precision() int32

Precision is the accuracy of the data type.

DECIMAL    : max # digits (must be >= Width/Scale)
INTERVAL   : max # fractional second digits
TIME       : max # fractional second digits
TIMETZ     : max # fractional second digits
TIMESTAMP  : max # fractional second digits
TIMESTAMPTZ: max # fractional second digits

Precision for time-related families has special rules for 0 -- see `precision_is_set` on the `InternalType` proto.

Precision is always 0 for other types.

func (*T) ProtoMessage

func (*T) ProtoMessage()

func (*T) Reset

func (m *T) Reset()

func (*T) SQLStandardName

func (t *T) SQLStandardName() string

SQLStandardName returns the type's name as it is specified in the SQL standard (or by Postgres for any non-standard types). This can be looked up for any type in Postgres using a query similar to this:

SELECT format_type(pg_typeof(1::int)::regtype, NULL)

func (*T) SQLStandardNameWithTypmod

func (t *T) SQLStandardNameWithTypmod(haveTypmod bool, typmod int) string

SQLStandardNameWithTypmod is like SQLStandardName but it also accepts a typmod argument, and a boolean which indicates whether or not a typmod was even specified. The expected results of this function should be, in Postgres:

SELECT format_type('thetype'::regype, typmod)

Generally, what this does with a non-0 typmod is append the scale, precision or length of a datatype to the name of the datatype. For example, a varchar(20) would appear as character varying(20) when provided the typmod value for varchar(20), which happens to be 24.

This function is full of special cases. See backend/utils/adt/format_type.c in Postgres.

func (*T) SQLString

func (t *T) SQLString() string

SQLString returns the CockroachDB native SQL string that can be used to reproduce the type via parsing the string as a type. It is used in error messages and also to produce the output of SHOW CREATE.

func (*T) Scale

func (t *T) Scale() int32

Scale is an alias method for Width, used for clarity for types in DecimalFamily.

func (*T) Size

func (t *T) Size() (n int)

Size returns the size, in bytes, of this type once it has been marshaled to a byte buffer. This is typically called to determine the size of the buffer that needs to be allocated before calling Marshal.

Marshal is part of the protoutil.Message interface.

func (*T) StableArrayTypeID

func (t *T) StableArrayTypeID() uint32

StableArrayTypeID returns the stable ID of the TypeDescriptor that backs the implicit array type for the type. This function only returns non-zero data for user defined types that aren't array types.

func (*T) StableTypeID

func (t *T) StableTypeID() uint32

StableTypeID returns the stable ID of the TypeDescriptor that backs this type. This function only returns non-zero data for user defined types.

func (*T) String

func (t *T) String() string

String returns the name of the type, similar to the Name method. However, it expands CollatedStringFamily, ArrayFamily, and TupleFamily types to be more descriptive.

TODO(andyk): It'd be nice to have this return SqlString() method output, since that is more descriptive.

func (*T) TelemetryName

func (t *T) TelemetryName() string

TelemetryName returns a name that is friendly for telemetry.

func (*T) TupleContents

func (t *T) TupleContents() []*T

TupleContents returns a slice containing the type of each tuple field. This is nil for non-TupleFamily types.

func (*T) TupleLabels

func (t *T) TupleLabels() []string

TupleLabels returns a slice containing the labels of each tuple field. This is nil for types not in the TupleFamily, or if the tuple type does not specify labels.

func (*T) TypeModifier

func (t *T) TypeModifier() int32

TypeModifier returns the type modifier of the type. This corresponds to the pg_attribute.atttypmod column. atttypmod records type-specific data supplied at table creation time (for example, the maximum length of a varchar column). The value will be -1 for types that do not need atttypmod.

func (*T) Unmarshal

func (t *T) Unmarshal(data []byte) error

Unmarshal deserializes a type from the given byte representation using gogo protobuf serialization rules. It is backwards-compatible with formats used by older versions of CRDB.

var t T
err := protoutil.Unmarshal(data, &t)

Unmarshal is part of the protoutil.Message interface.

func (*T) UserDefined

func (t *T) UserDefined() bool

UserDefined returns whether or not t is a user defined type.

func (*T) Width

func (t *T) Width() int32

Width is the size or scale of the type, such as number of bits or characters.

INT           : # of bits (64, 32, 16)
FLOAT         : # of bits (64, 32)
DECIMAL       : max # of digits after decimal point (must be <= Precision)
STRING        : max # of characters
COLLATEDSTRING: max # of characters
BIT           : max # of bits

Width is always 0 for other types.

func (*T) XXX_DiscardUnknown

func (m *T) XXX_DiscardUnknown()

func (*T) XXX_Marshal

func (m *T) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*T) XXX_Merge

func (m *T) XXX_Merge(src proto.Message)

func (*T) XXX_Size

func (m *T) XXX_Size() int

func (*T) XXX_Unmarshal

func (m *T) XXX_Unmarshal(b []byte) error

type UserDefinedTypeMetadata

type UserDefinedTypeMetadata struct {
	// Name is the resolved name of this type.
	Name *UserDefinedTypeName

	// enumData is non-nil iff the metadata is for an ENUM type.
	EnumData *EnumMetadata
}

UserDefinedTypeMetadata contains metadata needed for runtime operations on user defined types. The metadata must be read only.

type UserDefinedTypeName

type UserDefinedTypeName struct {
	Catalog string
	Schema  string
	Name    string
}

UserDefinedTypeName is a struct representing a qualified user defined type name. We redefine a common struct from higher level packages. We do so because proto will panic if any members of a proto struct are private. Rather than expose private members of higher level packages, we define a separate type here to be safe.

func MakeUserDefinedTypeName

func MakeUserDefinedTypeName(catalog, schema, name string) *UserDefinedTypeName

MakeUserDefinedTypeName creates a user defined type name.

func (UserDefinedTypeName) Basename

func (u UserDefinedTypeName) Basename() string

Basename returns the unqualified name.

func (UserDefinedTypeName) FQName

func (u UserDefinedTypeName) FQName() string

FQName returns the fully qualified name.

Directories

Path Synopsis
geo
Package geo contains the base types for spatial data type operations.
Package geo contains the base types for spatial data type operations.
geodist
Package geodist finds distances between two geospatial shapes.
Package geodist finds distances between two geospatial shapes.
geographiclib
Package geographiclib is a wrapper around the GeographicLib library.
Package geographiclib is a wrapper around the GeographicLib library.
geomfn
Package geomfn contains functions that are used for geometry-based builtins.
Package geomfn contains functions that are used for geometry-based builtins.
geoproj
Package geoproj contains functions that interface with the PROJ library.
Package geoproj contains functions that interface with the PROJ library.
geoprojbase
Package geoprojbase is a minimal dependency package that contains basic metadata and data structures for SRIDs and their CRS transformations.
Package geoprojbase is a minimal dependency package that contains basic metadata and data structures for SRIDs and their CRS transformations.
geos
Package geos is a wrapper around the spatial data types between the geo package and the GEOS C library.
Package geos is a wrapper around the spatial data types between the geo package and the GEOS C library.

Jump to

Keyboard shortcuts

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