github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/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 = "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 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 // AnyFamily is a special type family used during static analysis as a 359 // wildcard type that matches any other type, including scalar, array, and 360 // tuple types. Execution-time values should never have this type. As an 361 // example of its use, many SQL builtin functions allow an input value to be 362 // of any type, and so use this type in their static definitions. 363 // 364 // Canonical: types.Any 365 // Oid : T_anyelement 366 // 367 AnyFamily = 100; 368 369 // Int2VectorFamily deprecated in 19.1, since it now uses Oid. 370 reserved 200; 371 372 // OidVectorFamily deprecated in 19.1, since it now uses Oid. 373 reserved 201; 374 } 375 376 // IntervalDurationType represents a duration that can be used 377 // when defining an Interval Duration Field. 378 // See https://www.postgresql.org/docs/current/datatype-datetime.html. 379 enum IntervalDurationType { 380 // UNSET defaults to SECOND during evaluation. 381 // This indicates no typmod. 382 UNSET = 0; 383 384 YEAR = 1; 385 MONTH = 2; 386 DAY = 3; 387 HOUR = 4; 388 MINUTE = 5; 389 // SECOND is the only unit where precision can be added. 390 SECOND = 6; 391 392 // MILLISECOND is not technically part of the SQL standard for intervals, but we 393 // provide it as a field to allow code to parse intervals with a default unit 394 // of milliseconds, which is useful for some internal use cases like 395 // statement_timeout. 396 MILLISECOND = 7; 397 } 398 399 // IntervalDurationField represents precisions in intervals which are 400 // outside of the regular time precision syntax. 401 // i.e. instead of INTERVAL(6), we can have INTERVAL SECOND(6), INTERVAL MONTH, etc. 402 // This is represented as a bitmask on the first 4 bits of precision in postgres. 403 message IntervalDurationField { 404 // DurationType is the unit of measurement in which durations 405 // should truncate themselves to. 406 // This (unlike precision) gets truncated downward. 407 optional IntervalDurationType duration_type = 1 [(gogoproto.nullable) = false]; 408 // FromDurationType is the left side of the "duration field". 409 // i.e. in the `DurationType_1 TO DurationType_2` syntax, this represents `DurationType_1`. 410 // Note this is ignored, see https://www.postgresql.org/message-id/20110510040219.GD5617%40tornado.gateway.2wire.net. 411 optional IntervalDurationType from_duration_type = 2 [(gogoproto.nullable) = false]; 412 } 413 414 // GeoMetadata contains metadata associated with Geospatial data types. 415 message GeoMetadata { 416 optional int32 srid = 1 [(gogoproto.nullable)=false,(gogoproto.customname)="SRID",(gogoproto.casttype)="github.com/cockroachdb/cockroach/pkg/geo/geopb.SRID"]; 417 optional geopb.Shape shape = 2 [(gogoproto.nullable)=false]; 418 } 419 420 // PersistentUserDefinedTypeMetadata contains user defined type metadata 421 // that will be serialized to disk, unlike other user defined type metadata 422 // that is only stored in memory once a type is resolved. 423 message PersistentUserDefinedTypeMetadata { 424 // StableTypeID is the ID of the backing TypeDescriptor for this type. 425 optional uint32 stable_type_id = 1 426 [(gogoproto.nullable) = false, (gogoproto.customname) = "StableTypeID"]; 427 428 // StableArrayTypeID is the ID of the TypeDescriptor that defines the backs 429 // the automatically generated array type for this type. StableArrayTypeID 430 // is only set for user defined types that aren't arrays. 431 optional uint32 stable_array_type_id = 2 432 [(gogoproto.nullable) = false, (gogoproto.customname) = "StableArrayTypeID"]; 433 } 434 435 // T is a wrapper around InternalType. 436 message T { 437 option (gogoproto.typedecl) = false; 438 option (gogoproto.marshaler) = false; 439 option (gogoproto.unmarshaler) = false; 440 option (gogoproto.sizer) = false; 441 option (gogoproto.goproto_getters) = false; 442 option (gogoproto.goproto_stringer) = false; 443 // InternalType should never be directly referenced outside this package. The 444 // only reason it is exported is because gogoproto panics when printing the 445 // string representation of an unexported field. This is a problem when this 446 // struct is embedded in a larger struct (like a ColumnDescriptor). 447 optional InternalType internal_type = 1 [(gogoproto.nullable) = false]; 448 } 449 450 // InternalType is the protobuf encoding for SQL types. It is always wrapped by 451 // a T struct, and should never be used directly by outside packages. See the 452 // comment header for the T struct for more details. 453 message InternalType { 454 // Family specifies a group of types that are compatible with one another. 455 // See the header for the T.Family method for more details. 456 optional sql.sem.types.Family family = 1 [(gogoproto.nullable) = false]; 457 458 // Width is the size or scale of the type, such as number of bits or 459 // characters. See the T.Width method for more details. 460 optional int32 width = 2 [(gogoproto.nullable) = false]; 461 462 // Precision is the accuracy of the data type. See the T.Precision method for 463 // more details. This field was also by FLOAT pre-2.1 (this was incorrect.) 464 optional int32 precision = 3 [(gogoproto.nullable) = false]; 465 466 // ArrayDimensions is deprecated in 19.2, since it was never used. It 467 // previously contained the length of each dimension in the array. A 468 // dimension of -1 meant that no bound was specified for that dimension. If 469 // arrayDimensions was nil, then the array had one unbounded dimension. 470 repeated int32 array_dimensions = 4; 471 472 // Locale identifies a specific geographical, political, or cultural region that 473 // impacts various character-based operations such as sorting, pattern matching, 474 // and builtin functions like lower and upper. See the T.Locale method for 475 // more details. 476 optional string locale = 5; 477 478 // VisibleType is deprecated in 19.2, since it is now superseded by the Oid 479 // field. It previously contained an alias for any types where our internal 480 // representation is different than the user specification. Examples are INT4, 481 // FLOAT4, etc. Mostly for Postgres compatibility. 482 optional int32 visible_type = 6 [(gogoproto.nullable) = false]; 483 484 // ArrayElemType is deprecated in 19.2, since it is now superseded by the 485 // ArrayContents field. It previously contained the type family of array 486 // elements. The other array fields (width/precision/locale/etc) were used 487 // to store the other attributes of the array's element type. 488 optional sql.sem.types.Family array_elem_type = 7; 489 490 // TupleContents returns a slice containing the type of each tuple field. This 491 // is nil for non-TUPLE types. 492 repeated T tuple_contents = 8; 493 494 // TupleLabels returns a slice containing the labels of each tuple field. This 495 // is nil for non-TUPLE types, or if the TUPLE type does not specify labels. 496 repeated string tuple_labels = 9; 497 498 // Oid returns the type's Postgres Object ID. See the header for the T.Oid 499 // method for more details. For user-defined types, the OID value is an 500 // offset (oidext.CockroachPredefinedOIDMax) away from the stable_type_id 501 // field. This makes it easy to retrieve a type descriptor by OID. 502 optional uint32 oid = 10 [(gogoproto.nullable) = false, (gogoproto.customname) = "Oid", (gogoproto.customtype) = "github.com/lib/pq/oid.Oid"]; 503 504 // ArrayContents returns the type of array elements. This is nil for non-ARRAY 505 // types. 506 optional T array_contents = 11; 507 508 // TimePrecisionIsSet indicates whether the precision was explicitly set. 509 // It is currently in use for the TIME-related families and INTERVALs 510 // where a Precision of 0 indicated the default precision of 6 511 // in versions pre-20.1. 512 // The rules for Precision to use are as follows: 513 // * If Precision is > 0, then that is the precision. 514 // * If Precision is 0, it will default to 6 if TimePrecisionIsSet is false 515 // (for compatibility reasons). 516 // * Otherwise, Precision = 0 and TimePrecisionIsSet = true, so it is 517 // actually 0. 518 optional bool time_precision_is_set = 12 [(gogoproto.nullable) = false]; 519 520 // IntervalDurationField is populated for intervals, representing extra 521 // typmod or precision data that may be required. 522 optional IntervalDurationField interval_duration_field = 13; 523 524 // GeoMetadata is populated for geospatial types. 525 optional GeoMetadata geo_metadata = 14; 526 527 // UDTMetadata is populated for user defined types. 528 optional PersistentUserDefinedTypeMetadata udt_metadata = 15 [(gogoproto.customname) = "UDTMetadata"]; 529 }