cockroach: github.com/cockroachdb/cockroach/pkg/sql/types Index | Files

package types

import "github.com/cockroachdb/cockroach/pkg/sql/types"

Index

Package Files

oid.go types.go types.pb.go

Variables

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.
    OidVector = &T{InternalType: InternalType{
        Family: ArrayFamily, Oid: oid.T_oidvector, ArrayContents: Oid, Locale: &emptyLocale}}
)

Convenience list of pre-constructed OID-related types.

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, Oid: oid.T_time, 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: -1, 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: -1, 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, Oid: oid.T_interval, Locale: &emptyLocale}}

    // 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}}

    // 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,
        String,
        Bytes,
        TimestampTZ,
        Oid,
        Uuid,
        INet,
        Time,
        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}}

    // 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}}

    // 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.
    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).

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

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

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",
    20:  "TupleFamily",
    21:  "BitFamily",
    100: "AnyFamily",
}
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,
    "TupleFamily":          20,
    "BitFamily":            21,
    "AnyFamily":            100,
}
var OidToType = map[oid.Oid]*T{
    oid.T_anyelement:   Any,
    oid.T_bit:          typeBit,
    oid.T_bool:         Bool,
    oid.T_bpchar:       typeBpChar,
    oid.T_bytea:        Bytes,
    oid.T_char:         typeQChar,
    oid.T_date:         Date,
    oid.T_float4:       Float4,
    oid.T_float8:       Float,
    oid.T_int2:         Int2,
    oid.T_int2vector:   Int2Vector,
    oid.T_int4:         Int4,
    oid.T_int8:         Int,
    oid.T_inet:         INet,
    oid.T_interval:     Interval,
    oid.T_jsonb:        Jsonb,
    oid.T_name:         Name,
    oid.T_numeric:      Decimal,
    oid.T_oid:          Oid,
    oid.T_oidvector:    OidVector,
    oid.T_record:       AnyTuple,
    oid.T_regclass:     RegClass,
    oid.T_regnamespace: RegNamespace,
    oid.T_regproc:      RegProc,
    oid.T_regprocedure: RegProcedure,
    oid.T_regtype:      RegType,
    oid.T_text:         String,
    oid.T_time:         Time,
    oid.T_timestamp:    Timestamp,
    oid.T_timestamptz:  TimestampTZ,
    oid.T_unknown:      Unknown,
    oid.T_uuid:         Uuid,
    oid.T_varbit:       VarBit,
    oid.T_varchar:      VarChar,
}

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().

func CheckArrayElementType Uses

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 Uses

func IsAdditiveType(t *T) bool

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

func IsDateTimeType Uses

func IsDateTimeType(t *T) bool

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

func IsStringType Uses

func IsStringType(t *T) bool

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

func IsValidArrayElementType Uses

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 Uses

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).

type Family Uses

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
    // 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
    // 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 Uses

func (x Family) Enum() *Family

func (Family) EnumDescriptor Uses

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

func (Family) String Uses

func (x Family) String() string

func (*Family) UnmarshalJSON Uses

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

type InternalType Uses

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 `protobuf:"varint,7,opt,name=array_elem_type,json=arrayElemType,enum=cockroach.sql.sem.types.Family" json:"array_elem_type,omitempty"`
    // 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,customtype=T" json:"tuple_contents"`
    // 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.
    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,customtype=T" json:"array_contents,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 Uses

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

func (*InternalType) Identical Uses

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

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

func (*InternalType) Marshal Uses

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

func (*InternalType) MarshalTo Uses

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

func (*InternalType) ProtoMessage Uses

func (*InternalType) ProtoMessage()

func (*InternalType) Reset Uses

func (m *InternalType) Reset()

func (*InternalType) Size Uses

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

func (*InternalType) String Uses

func (m *InternalType) String() string

func (*InternalType) Unmarshal Uses

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

func (*InternalType) XXX_DiscardUnknown Uses

func (m *InternalType) XXX_DiscardUnknown()

func (*InternalType) XXX_Marshal Uses

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

func (*InternalType) XXX_Merge Uses

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

func (*InternalType) XXX_Size Uses

func (m *InternalType) XXX_Size() int

func (*InternalType) XXX_Unmarshal Uses

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

type T Uses

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
}

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 | | 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.

func MakeArray Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 MakeLabeledTuple Uses

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 Uses

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 Uses

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 Uses

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 Uses

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.

func MakeTimestamp Uses

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.

func MakeTimestampTZ Uses

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.

func MakeTuple Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

func (t *T) DebugString() string

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

func (*T) Equal Uses

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

Equal is for use in generated protocol buffer code only.

func (*T) Equivalent Uses

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) Family Uses

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) Identical Uses

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 Uses

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) IsAmbiguous Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

func (t *T) Precision() int32

Precision is the accuracy of the data type.

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

For TIMESTAMP and TIMESTAMP TZ, the precision field is -1 for a default precision value of 6. Precision is always 0 for other types.

func (*T) ProtoMessage Uses

func (t *T) ProtoMessage()

ProtoMessage is the protobuf marker method. It is part of the protoutil.Message interface.

func (*T) Reset Uses

func (t *T) Reset()

Reset clears the type instance. It is part of the protoutil.Message interface.

func (*T) SQLStandardName Uses

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 Uses

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 Uses

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 Uses

func (t *T) Scale() int32

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

func (*T) Size Uses

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) String Uses

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) TupleContents Uses

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 Uses

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) Unmarshal Uses

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) Width Uses

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.

Package types imports 11 packages (graph) and is imported by 91 packages. Updated 2019-09-14. Refresh now. Tools for package owners.