MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / registerDataTypeTuple

Function registerDataTypeTuple

src/DataTypes/DataTypeTuple.cpp:497–712  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

495
496
497void registerDataTypeTuple(DataTypeFactory & factory)
498{
499 factory.registerDataType("Tuple", create, DataTypeFactory::Case::Sensitive, Documentation{
500 .description = R"DOCS_MD(
501A tuple of elements, each having an individual [type](/sql-reference/data-types). Tuple must contain at least one element.
502
503Tuples are used for temporary column grouping. Columns can be grouped when an IN expression is used in a query, and for specifying certain formal parameters of lambda functions. For more information, see the sections [IN operators](../../sql-reference/operators/in.md) and [Higher order functions](/sql-reference/functions/overview#higher-order-functions).
504
505Tuples can be the result of a query. In this case, for text formats other than JSON, values are comma-separated in `()`. In JSON formats, tuples are output as arrays (in `[]`).
506
507## Creating Tuples {#creating-tuples}
508
509You can use a function to create a tuple:
510
511```sql
512tuple(T1, T2, ...)
513```
514
515Example of creating a tuple:
516
517```sql
518SELECT tuple(1, 'a') AS x, toTypeName(x)
519```
520
521```text
522┌─x───────┬─toTypeName(tuple(1, 'a'))─┐
523│ (1,'a') │ Tuple(UInt8, String) │
524└─────────┴───────────────────────────┘
525```
526
527A Tuple can contain a single element
528
529Example:
530
531```sql
532SELECT tuple('a') AS x;
533```
534
535```text
536┌─x─────┐
537│ ('a') │
538└───────┘
539```
540
541Syntax `(tuple_element1, tuple_element2)` may be used to create a tuple of several elements without calling the `tuple()` function.
542
543Example:
544
545```sql
546SELECT (1, 'a') AS x, (today(), rand(), 'someString') AS y, ('a') AS not_a_tuple;
547```
548
549```text
550┌─x───────┬─y──────────────────────────────────────┬─not_a_tuple─┐
551│ (1,'a') │ ('2022-09-21',2006973416,'someString') │ a │
552└─────────┴────────────────────────────────────────┴─────────────┘
553```
554

Callers 1

DataTypeFactoryMethod · 0.85

Calls 1

registerDataTypeMethod · 0.80

Tested by

no test coverage detected