github.com/cockroachdb/cockroachdb-parser@v0.23.3-0.20240213214944-911057d40c9a/pkg/sql/types/types.proto (about)

     1  // Copyright 2015 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  // Cannot be proto3 because we use nullable primitives.
    12  syntax = "proto2";
    13  package cockroach.sql.sem.types;
    14  option go_package = "github.com/cockroachdb/cockroach/pkg/sql/types";
    15  
    16  import "gogoproto/gogo.proto";
    17  import "geo/geopb/geopb.proto";
    18  
    19  // See the comment header for the T.Family method for more details.
    20  enum Family {
    21      option (gogoproto.goproto_enum_prefix) = false;
    22  
    23      // BoolFamily is the family of boolean true/false types.
    24      //
    25      //   Canonical: types.Bool
    26      //   Oid      : T_bool
    27      //
    28      // Examples:
    29      //   BOOL
    30      //
    31      BoolFamily = 0;
    32  
    33      // IntFamily is the family of signed integer types.
    34      //
    35      //   Canonical: types.Int
    36      //   Oid      : T_int8, T_int4, T_int2
    37      //   Width    : 64, 32, 16
    38      //
    39      // Examples:
    40      //   INT
    41      //   INT8
    42      //   INT4
    43      //
    44      IntFamily = 1;
    45  
    46      // FloatFamily is the family of base-2 floating-point types (IEEE 754).
    47      //
    48      //   Canonical: types.Float
    49      //   Oid      : T_float8, T_float4
    50      //   Width    : 64, 32
    51      //
    52      // Examples:
    53      //   FLOAT8
    54      //   FLOAT4
    55      //
    56      FloatFamily = 2;
    57  
    58      // DecimalFamily is the family of base-10 floating and fixed point types.
    59      //
    60      //   Canonical    : types.Decimal
    61      //   Oid          : T_numeric
    62      //   Precision    : max # decimal digits (0 = no specified limit)
    63      //   Width (Scale): # digits after decimal point (0 = no specified limit)
    64      //
    65      // Examples:
    66      //   DECIMAL
    67      //   DECIMAL(10)
    68      //   DECIMAL(10,3)
    69      //
    70      DecimalFamily = 3;
    71  
    72      // DateFamily is the family of date types that store only year/month/day with
    73      // no time component.
    74      //
    75      //   Canonical: types.Date
    76      //   Oid      : T_date
    77      //
    78      // Examples:
    79      //   DATE
    80      //
    81      DateFamily = 4;
    82  
    83      // TimestampFamily is the family of date types that store a year/month/day
    84      // date component, as well as an hour/minute/second time component. There is
    85      // no timezone component (see TIMESTAMPTZ). Seconds can have varying precision
    86      // (defaults to microsecond precision). Currently, only microsecond precision
    87      // is supported.
    88      //
    89      //   Canonical: types.Timestamp
    90      //   Oid      : T_timestamp
    91      //   Precision: fractional seconds (3 = ms, 0,6 = us, 9 = ns, etc.)
    92      //
    93      // Examples:
    94      //   TIMESTAMP
    95      //   TIMESTAMP(6)
    96      //
    97      TimestampFamily = 5;
    98  
    99      // IntervalFamily is the family of types describing a duration of time.
   100      // Currently, only microsecond precision is supported.
   101      //
   102      //   Canonical: types.Interval
   103      //   Oid      : T_interval
   104      //
   105      // Examples:
   106      //   INTERVAL
   107      //
   108      IntervalFamily = 6;
   109  
   110      // StringFamily is the family of types containing Unicode textual strings.
   111      // This family includes types constructed by STRING, VARCHAR, CHAR, and "char"
   112      // column type definitions (CHAR and "char" are distinct PG types). Note
   113      // that while STRING and VARCHAR have no default width limit, CHAR has a
   114      // default width of 1.
   115      // TODO(andyk): "char" should have default width of 1 as well, but doesn't.
   116      //
   117      //   Canonical: types.String
   118      //   Oid      : T_text, T_varchar, T_bpchar, T_char
   119      //   Width    : max # characters (0 = no specified limit)
   120      //
   121      // Examples:
   122      //   STRING
   123      //   TEXT
   124      //   VARCHAR(10)
   125      //   CHAR
   126      //
   127      StringFamily = 7;
   128  
   129      // BytesFamily is the family of types containing a list of raw byte values.
   130      //
   131      //   Canonical: types.BYTES
   132      //   Oid      : T_bytea
   133      //
   134      // Examples:
   135      //   BYTES
   136      //
   137      BytesFamily = 8;
   138  
   139      // TimestampTZFamily is the family of date types that store a year/month/day
   140      // date component, as well as an hour/minute/second time component, along with
   141      // a timezone. Seconds can have varying precision (defaults to microsecond
   142      // precision). Currently, only microsecond precision is supported.
   143      //
   144      //   Canonical: types.TimestampTZ
   145      //   Oid      : T_timestamptz
   146      //   Precision: fractional seconds (3 = ms, 0,6 = us, 9 = ns, etc.)
   147      //
   148      // Examples:
   149      //   TIMESTAMPTZ
   150      //   TIMESTAMPTZ(6)
   151      //
   152      TimestampTZFamily = 9;
   153  
   154      // CollatedStringFamily is the family of types containing Unicode textual
   155      // strings with an associated COLLATE value that specifies the locale used
   156      // for various character-based operations such as sorting, pattern matching,
   157      // and builtin functions like lower and upper.
   158      //
   159      //   Oid      : T_text, T_varchar, T_bpchar, T_char
   160      //   Width    : max # characters (0 = no specified limit)
   161      //   Locale   : name of locale (e.g. EN or DE)
   162      //
   163      // Examples:
   164      //   STRING COLLATE en
   165      //   VARCHAR(10) COLLATE de
   166      //
   167      CollatedStringFamily = 10;
   168  
   169      // NAME deprecated in 19.1, since it now uses Oid.
   170      reserved 11;
   171  
   172      // OidFamily is the family of types containing Postgres Object ID (Oid)
   173      // values. Oids are integer values that identify some object in the database,
   174      // like a type, relation, or procedure.
   175      //
   176      //   Canonical: types.Oid
   177      //   Oid      : T_oid, T_regclass, T_regproc, T_regprocedure, T_regtype,
   178      //              T_regnamespace, T_regrole
   179      //
   180      // Examples:
   181      //   OID
   182      //   REGCLASS
   183      //   REGPROC
   184      //
   185      // TODO(andyk): Oids should be part of the IntFamily, since they are treated
   186      //              as equivalent to ints by PG.
   187      OidFamily = 12;
   188  
   189      // UnknownFamily is a special type family that tags expressions that
   190      // statically evaluate to NULL. An UnknownFamily expression *must* be NULL.
   191      // But the inverse is not true, since other types allow NULL values as well.
   192      // UnknownFamily types are not supported as a table column type, but can be
   193      // transferred through DistSQL streams.
   194      //
   195      //   Canonical: types.Unknown
   196      //   Oid      : T_unknown
   197      //
   198      UnknownFamily = 13;
   199  
   200      // UuidFamily is the family of types containing universally unique
   201      // identifiers. A UUID is a 128-bit quantity that is very unlikely to ever be
   202      // generated again, and so can be relied on to be distinct from all other UUID
   203      // values.
   204      //
   205      //   Canonical: types.Uuid
   206      //   Oid      : T_uuid
   207      //
   208      // Examples:
   209      //   UUID
   210      //
   211      UuidFamily = 14;
   212  
   213      // ArrayFamily is a family of non-scalar types that contain an ordered list of
   214      // elements. The elements of an array must all share the same type. Elements
   215      // can have have any type, including ARRAY. However, while the types package
   216      // supports nested arrays, other parts of CRDB do not currently support them.
   217      // Also, the length of array dimension(s) are ignored by PG and CRDB (e.g.
   218      // an array of length 11 could be inserted into a column declared as INT[11]).
   219      //
   220      // Array OID values are special. Rather than having a single T_array OID,
   221      // Postgres defines a separate OID for each possible array element type.
   222      // Here are some examples:
   223      //
   224      //   T__int8: array of int8 values
   225      //   T__text: array of text values
   226      //
   227      // Notice that each array OID has double underscores to distinguish it from
   228      // the OID of the scalar type it contains.
   229      //
   230      //   Oid          : T__int, T__text, T__numeric, etc.
   231      //   ArrayContents: types.T of the array element type
   232      //
   233      // Examples:
   234      //   INT[]
   235      //   VARCHAR(10)[] COLLATE EN
   236      //   DECIMAL(10,1)[]
   237      //   TIMESTAMP[5]
   238      //
   239      ArrayFamily = 15;
   240  
   241      // INetFamily is the family of types containing IPv4 or IPv6 network address
   242      // identifiers (e.g. 192.168.100.128/25 or FE80:CD00:0:CDE:1257:0:211E:729C).
   243      //
   244      //   Canonical: types.INet
   245      //   Oid      : T_inet
   246      //
   247      // Examples:
   248      //   INET
   249      //
   250      INetFamily = 16;
   251  
   252      // TimeFamily is the family of date types that store only hour/minute/second
   253      // with no date component. There is no timezone component. Seconds can have
   254      // varying precision (defaults to microsecond precision). Currently, only
   255      // microsecond precision is supported.
   256      //
   257      //   Canonical: types.Time
   258      //   Oid      : T_time
   259      //   Precision: fractional seconds (3 = ms, 0,6 = us, 9 = ns, etc.)
   260      //
   261      // Examples:
   262      //   TIME
   263      //   TIME(6)
   264      //
   265      TimeFamily = 17;
   266  
   267      // JsonFamily is the family of types containing JavaScript Object Notation
   268      // (JSON) values. Currently, CRDB only supports JSONB values, which are stored
   269      // in a decomposed binary format.
   270      //
   271      //   Canonical: types.Jsonb
   272      //   Oid      : T_jsonb
   273      //
   274      // Examples:
   275      //   JSON
   276      //   JSONB
   277      //
   278      JsonFamily = 18;
   279  
   280      // TimeTZFamily is the family of date types that store only hour/minute/second
   281      // and timestamp components, with no date component. Seconds can have
   282      // varying precision (defaults to microsecond precision). Currently, only
   283      // microsecond precision is supported.
   284      //
   285      //   Canonical: types.TimeTZ
   286      //   Oid      : T_timetz
   287      //   Precision: fractional seconds (3 = ms, 0,6 = us, 9 = ns, etc.)
   288      //
   289      // Examples:
   290      //   TIMETZ
   291      //
   292      TimeTZFamily = 19;
   293  
   294      // TupleFamily is a family of non-scalar structural types that describes the
   295      // fields of a row or record. The fields can be of any type, including nested
   296      // tuple and array types. Fields can also have optional labels. Currently,
   297      // CRDB does not support tuple types as column types, but it is possible to
   298      // construct tuples using the ROW function or tuple construction syntax.
   299      //
   300      //   Oid          : T_record
   301      //   TupleContents: []*types.T of each tuple field
   302      //   TupleLabels  : []string of each tuple label
   303      //
   304      // Examples:
   305      //   (1, 'foo')
   306      //   ((1, 'foo') AS num, str)
   307      //   ROW(1, 'foo')
   308      //   (ROW(1, 'foo') AS num, str)
   309      //
   310      TupleFamily = 20;
   311  
   312      // BitFamily is the family of types containing ordered lists of bit values
   313      // (0 or 1). Note that while VARBIT has no default width limit, BIT has a
   314      // default width limit of 1.
   315      //
   316      //   Canonical: types.VarBit
   317      //   Oid      : T_varbit, T_bit
   318      //   Width    : max # of bits (0 = no specified limit)
   319      //
   320      // Examples:
   321      //   VARBIT
   322      //   VARBIT(10)
   323      //   BIT
   324      //   BIT(10)
   325      //
   326      BitFamily = 21;
   327  
   328      // GeometryFamily is a family that supports the Geometry geospatial type,
   329      // which is compatible with PostGIS's Geometry implementation.
   330      //
   331      //   Canonical: types.Geometry
   332      //   Oid      : oidext.T_geometry
   333      //
   334      // Examples:
   335      //   GEOMETRY
   336      //   GEOMETRY(LINESTRING)
   337      //   GEOMETRY(LINESTRING, SRID)
   338      GeometryFamily = 22;
   339  
   340      // GeographyFamily is a family that supports the Geography geospatial type,
   341      // which is compatible with PostGIS's Geography implementation.
   342      //
   343      //   Canonical: types.Geography
   344      //   Oid      : oidext.T_geography
   345      //
   346      // Examples:
   347      //   GEOGRAPHY
   348      //   GEOGRAPHY(LINESTRING)
   349      //   GEOGRAPHY(LINESTRING, SRID)
   350      GeographyFamily = 23;
   351  
   352      // EnumFamily is a family that represents all ENUM types. ENUM types
   353      // have data about the ENUM defined in a TypeDescriptor. The ID of
   354      // the TypeDescriptor that backs this ENUM is stored in the StableTypeID
   355      // field. It does not have a canonical form.
   356      EnumFamily = 24;
   357  
   358      // Box2DFamily is a family representing the box2d type. This is compatible
   359      // with PostGIS's box2d implementation.
   360      //
   361      //   Canonical: types.Box2D
   362      //   Oid      : oidext.T_box2d
   363      //
   364      // Examples:
   365      //   Box2D
   366      Box2DFamily = 25;
   367  
   368      // VoidFamily is a family representing the void type.
   369      //
   370      //   Canonical: types.Void
   371      //   Oid      : T_void
   372      //
   373      // Examples:
   374      //   Void
   375      VoidFamily = 26;
   376  
   377      // EncodedKeyFamily is a special type family used internally for inverted
   378      // index keys, which do not fully encode an object.
   379      EncodedKeyFamily = 27;
   380  
   381      // TSQueryFamily is a type family for the TSQuery type, which is the type
   382      // of full text search queries.
   383      //   Canonical: types.TSQuery
   384      //   Oid      : T_tsquery
   385      TSQueryFamily = 28;
   386  
   387      // TSVectorFamily is a type family for the TSVector type, which is the type
   388      // of full text search document representations.
   389      //   Canonical: types.TSVector
   390      //   Oid      : T_tsvector
   391      TSVectorFamily = 29;
   392  
   393      // PGLSNFamily is a type family for the pg_lsn type, which is the type
   394      // representing PG LSN objects.
   395      //   Canonical: types.PGLSN
   396      //   Oid      : T_pg_lsn
   397      PGLSNFamily = 30;
   398  
   399      // RefCursorFamily is a type family for the refcursor type, which is the
   400      // type representing PLpgSQL cursors.
   401      //   Canonical: types.RefCursor
   402      //   Oid      : T_refcursor
   403      RefCursorFamily = 31;
   404  
   405      // AnyFamily is a special type family used during static analysis as a
   406      // wildcard type that matches any other type, including scalar, array, and
   407      // tuple types. Execution-time values should never have this type. As an
   408      // example of its use, many SQL builtin functions allow an input value to be
   409      // of any type, and so use this type in their static definitions.
   410      //
   411      //   Canonical: types.Any
   412      //   Oid      : T_anyelement
   413      //
   414      AnyFamily = 100;
   415  
   416      // Int2VectorFamily deprecated in 19.1, since it now uses Oid.
   417      reserved 200;
   418  
   419      // OidVectorFamily deprecated in 19.1, since it now uses Oid.
   420      reserved 201;
   421  }
   422  
   423  // IntervalDurationType represents a duration that can be used
   424  // when defining an Interval Duration Field.
   425  // See https://www.postgresql.org/docs/current/datatype-datetime.html.
   426  enum IntervalDurationType {
   427    // UNSET defaults to SECOND during evaluation.
   428    // This indicates no typmod.
   429    UNSET = 0;
   430  
   431    YEAR = 1;
   432    MONTH = 2;
   433    DAY = 3;
   434    HOUR = 4;
   435    MINUTE = 5;
   436    // SECOND is the only unit where precision can be added.
   437    SECOND = 6;
   438  
   439    // MILLISECOND is not technically part of the SQL standard for intervals, but we
   440    // provide it as a field to allow code to parse intervals with a default unit
   441    // of milliseconds, which is useful for some internal use cases like
   442    // statement_timeout.
   443    MILLISECOND = 7;
   444  }
   445  
   446  // IntervalDurationField represents precisions in intervals which are
   447  // outside of the regular time precision syntax.
   448  // i.e. instead of INTERVAL(6), we can have INTERVAL SECOND(6), INTERVAL MONTH, etc.
   449  // This is represented as a bitmask on the first 4 bits of precision in postgres.
   450  message IntervalDurationField {
   451    // DurationType is the unit of measurement in which durations
   452    // should truncate themselves to.
   453    // This (unlike precision) gets truncated downward.
   454    optional IntervalDurationType duration_type = 1 [(gogoproto.nullable) = false];
   455    // FromDurationType is the left side of the "duration field".
   456    // i.e. in the `DurationType_1 TO DurationType_2` syntax, this represents `DurationType_1`.
   457    // Note this is ignored, see https://www.postgresql.org/message-id/20110510040219.GD5617%40tornado.gateway.2wire.net.
   458    optional IntervalDurationType from_duration_type = 2 [(gogoproto.nullable) = false];
   459  }
   460  
   461  // GeoMetadata contains metadata associated with Geospatial data types.
   462  message GeoMetadata {
   463    optional int32 srid = 1 [(gogoproto.nullable)=false,(gogoproto.customname)="SRID",(gogoproto.casttype)="github.com/cockroachdb/cockroach/pkg/geo/geopb.SRID"];
   464    optional geopb.ShapeType shape_type = 2 [(gogoproto.nullable)=false];
   465  }
   466  
   467  // PersistentUserDefinedTypeMetadata contains user defined type metadata
   468  // that will be serialized to disk, unlike other user defined type metadata
   469  // that is only stored in memory once a type is resolved.
   470  message PersistentUserDefinedTypeMetadata {
   471    // ArrayTypeOID is the OID of the array type for this user defined type. It
   472    // is only set for user defined types that aren't arrays.
   473    optional uint32 array_type_oid = 2
   474      [(gogoproto.nullable) = false, (gogoproto.customname) = "ArrayTypeOID", (gogoproto.customtype) = "github.com/lib/pq/oid.Oid"];
   475  
   476    reserved 1;
   477  }
   478  
   479  // T is a wrapper around InternalType.
   480  message T {
   481      option (gogoproto.typedecl) = false;
   482      option (gogoproto.marshaler) = false;
   483      option (gogoproto.unmarshaler) = false;
   484      option (gogoproto.sizer) = false;
   485      option (gogoproto.goproto_getters) = false;
   486      option (gogoproto.goproto_stringer) = false;
   487      // InternalType should never be directly referenced outside this package. The
   488      // only reason it is exported is because gogoproto panics when printing the
   489      // string representation of an unexported field. This is a problem when this
   490      // struct is embedded in a larger struct (like a ColumnDescriptor).
   491      optional InternalType internal_type = 1 [(gogoproto.nullable) = false];
   492  }
   493  
   494  // InternalType is the protobuf encoding for SQL types. It is always wrapped by
   495  // a T struct, and should never be used directly by outside packages. See the
   496  // comment header for the T struct for more details.
   497  message InternalType {
   498      // Family specifies a group of types that are compatible with one another.
   499      // See the header for the T.Family method for more details.
   500      optional sql.sem.types.Family family = 1 [(gogoproto.nullable) = false];
   501  
   502      // Width is the size or scale of the type, such as number of bits or
   503      // characters. See the T.Width method for more details.
   504      optional int32 width = 2 [(gogoproto.nullable) = false];
   505  
   506      // Precision is the accuracy of the data type. See the T.Precision method for
   507      // more details. This field was also by FLOAT pre-2.1 (this was incorrect.)
   508      optional int32 precision = 3 [(gogoproto.nullable) = false];
   509  
   510      // ArrayDimensions is deprecated in 19.2, since it was never used. It
   511      // previously contained the length of each dimension in the array. A
   512      // dimension of -1 meant that no bound was specified for that dimension. If
   513      // arrayDimensions was nil, then the array had one unbounded dimension.
   514      repeated int32 array_dimensions = 4;
   515  
   516      // Locale identifies a specific geographical, political, or cultural region that
   517      // impacts various character-based operations such as sorting, pattern matching,
   518      // and builtin functions like lower and upper. See the T.Locale method for
   519      // more details.
   520      optional string locale = 5;
   521  
   522      // VisibleType is deprecated in 19.2, since it is now superseded by the Oid
   523      // field. It previously contained an alias for any types where our internal
   524      // representation is different than the user specification. Examples are INT4,
   525      // FLOAT4, etc. Mostly for Postgres compatibility.
   526      optional int32 visible_type = 6 [(gogoproto.nullable) = false];
   527  
   528      // ArrayElemType is deprecated in 19.2, since it is now superseded by the
   529      // ArrayContents field. It previously contained the type family of array
   530      // elements. The other array fields (width/precision/locale/etc) were used
   531      // to store the other attributes of the array's element type.
   532      optional sql.sem.types.Family array_elem_type = 7;
   533  
   534      // TupleContents returns a slice containing the type of each tuple field. This
   535      // is nil for non-TUPLE types.
   536      repeated T tuple_contents = 8;
   537  
   538      // TupleLabels returns a slice containing the labels of each tuple field. This
   539      // is nil for non-TUPLE types, or if the TUPLE type does not specify labels.
   540      repeated string tuple_labels = 9;
   541  
   542      // Oid returns the type's Postgres Object ID. See the header for the T.Oid
   543      // method for more details. For user-defined types, the OID value is an
   544      // offset (oidext.CockroachPredefinedOIDMax) away from the stable_type_id
   545      // field. This makes it easy to retrieve a type descriptor by OID.
   546      optional uint32 oid = 10 [(gogoproto.nullable) = false, (gogoproto.customname) = "Oid", (gogoproto.customtype) = "github.com/lib/pq/oid.Oid"];
   547  
   548      // ArrayContents returns the type of array elements. This is nil for non-ARRAY
   549      // types.
   550      optional T array_contents = 11;
   551  
   552      // TimePrecisionIsSet indicates whether the precision was explicitly set.
   553      // It is currently in use for the TIME-related families and INTERVALs
   554      // where a Precision of 0 indicated the default precision of 6
   555      // in versions pre-20.1.
   556      // The rules for Precision to use are as follows:
   557      //   * If Precision is > 0, then that is the precision.
   558      //   * If Precision is 0, it will default to 6 if TimePrecisionIsSet is false
   559      //    (for compatibility reasons).
   560      //   * Otherwise, Precision = 0 and TimePrecisionIsSet = true, so it is
   561      //     actually 0.
   562      optional bool time_precision_is_set = 12 [(gogoproto.nullable) = false];
   563  
   564      // IntervalDurationField is populated for intervals, representing extra
   565      // typmod or precision data that may be required.
   566      optional IntervalDurationField interval_duration_field = 13;
   567  
   568      // GeoMetadata is populated for geospatial types.
   569      optional GeoMetadata geo_metadata = 14;
   570  
   571      // UDTMetadata is populated for user defined types that are not arrays.
   572      optional PersistentUserDefinedTypeMetadata udt_metadata = 15 [(gogoproto.customname) = "UDTMetadata"];
   573  }