# Data Types

DeltaStream's data types are similar to SQL standard's data types. They are used to declare the value type for columns in relations or input/output parameters in functions.

## Primitive Data Types

### Boolean

| `BOOLEAN` | Boolean value representing `true` or `false.` |
| --------- | --------------------------------------------- |

### Character string

| <p><code>VARCHAR</code><br><code>VARCHAR(n)</code></p> | <p>Variable-length character string.<br>Type parameter <code>n</code> represents maximum length of string (number of code points) and has to be an integer between <code>1</code>and <code>2,147,483,647</code>.<br>If no length specified, maximum length is picked.</p> |
| ------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

### Numeric

| `TINYINT`                                                 | <p>1-byte signed integer.<br>It can hold an integer value between <code>-128</code> and <code>127</code>.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| --------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `SMALLINT`                                                | <p>2-byte signed integer.<br>It can hold an integer value between <code>-32,768</code> and <code>32,767</code>.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `INTEGER`                                                 | <p>4-byte signed integer.<br>It can hold an integer value between <code>-2^31</code> and <code>2^31-1</code>.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `BIGINT`                                                  | <p>8-byte signed integer.<br>It can hold an integer value between <code>-2^63</code> and <code>2^63-1</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `FLOAT`                                                   | 4-byte variable precision floating point number.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `DOUBLE`                                                  | 8-byte variable precision floating point number.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| <p><code>DECIMAL</code><br><code>DECIMAL(p, s)</code></p> | <p>Decimal number with fixed precision and scale.<br>Decimal type accepts two type parameters: <code>p</code>: for <em>precision</em> and <code>s</code> for <em>scale</em>.<br><em>Precision</em> is the maximum total number of digits to be stored in the number (an integer value between <code>1</code> and <code>38</code>).<br><em>Scale</em> is the number of decimal digits to the right of the decimal point (an integer value between <code>0</code> and <code>p</code>).<br>If no type parameters specified, default precision of <code>10</code> and default scale of <code>0</code> are picked.</p> |

### Date and Time

| `DATE`                                                                                                                                                                | Calendar date consisting of `year-month-day` with values between `0000-01-01` and `9999-12-31`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><code>TIME</code><br><code>TIME(p)</code></p>                                                                                                                      | <p>Time of day, without time zone, consisting of <code>hour:minute:second\[.fractional]</code> (up to nanosecond precision) with values between <code>00:00:00.000000000</code> and <code>23:59:59.999999999</code>.<br>Type parameter <code>p</code> represents <code>precision</code> which is the number of digits of fractional seconds (an integer between <code>0</code> and <code>9</code>).<br>If no precision specified, default precision of <code>0</code> is picked.</p>                                                                                                                                                                                                                                                                                                                                          |
| <p><code>TIMESTAMP</code><br><code>TIMESTAMP(p)</code></p>                                                                                                            | <p>Timestamp, without time zone, consisting of <code>year-month-day hour:minute:second\[.fractional]</code> (up to nanosecond precision) with values between <code>0000-01-01 00:00:00.000000000</code> and <code>9999-12-31 23:59:59.999999999</code>.<br>Type parameter <code>p</code> represents <code>precision</code> which is the number of digits of fractional seconds (an integer between <code>0</code> and <code>9</code>).<br>If no precision specified, default precision of <code>6</code> is picked.<br>There are two types of formats for timestamps that are supported – <code>sql</code> and <code>iso8601</code>.</p>                                                                                                                                                                                      |
| <p><code>TIMESTAMP WITH LOCAL TIME ZONE</code><br><code>TIMESTAMP(p) WITH LOCAL TIME ZONE</code><br><code>TIMESTAMP\_LTZ</code><br><code>TIMESTAMP\_LTZ(p)</code></p> | <p>Timestamp with local time zone consisting of <code>year-month-day hour:minute:second\[.fractional] zone</code> (up to nanosecond precision) with values between <code>0000-01-01 00:00:00.000000000Z</code> to <code>9999-12-31 23:59:59.999999999Z</code>.<br>Values for this type assume <code>Instant</code> semantics in the UTC time zone.<br>Type parameter <code>p</code> represents <code>precision</code> which is the number of digits of fractional seconds (an integer between <code>0</code> and <code>9</code>).<br>If no precision specified, default precision of <code>6</code> is picked. <code>TIMESTAMP\_LTZ</code> is a synonym for <code>TIMESTAMP WITH LOCAL TIME ZONE</code>.<br>There are two types of formats for timestamps that are supported – <code>sql</code> and <code>iso8601</code>.</p> |

### Binary string

| <p><code>VARBINARY</code><br><code>VARBINARY(n)</code><br><code>BYTES</code></p> | <p>Variable-length sequence of bytes.<br>Type parameter <code>n</code> represents maximum length of sequence (number of bytes) and has to be an integer between <code>1</code>and <code>2,147,483,647</code>.<br>If no length specified, default length of <code>1</code> is picked.<br><code>BYTES</code> is a synonym for <code>VARBINARY</code> with maximum length (<code>VARBINARY(2147483647)</code>).</p> |
| -------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

## Constructed Data Types

| `ARRAY<t>`           | <p>Array of elements with same data type.<br>Type parameter <code>t</code> is required and represents data type of array elements.<br>The maximum number of elements of an array can not be specified and is fixed at <code>2,147,483,647</code>.<br>Similar to SQL, arrays are one-indexed (first element is at index <code>1</code>) and a given element can be accessed using the <code>\[]</code> operator with the index.<br></p><p><strong>Example.</strong> In a relation DDL statement, the expression <code>employees ARRAY\<VARCHAR></code> declares a column named <code>employees</code> with values of type array holding character strings. <code>employees\[6]</code> is used to access the 6th element in a given value from this column.</p>                                                                                                                                                                                                                                            |
| -------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `MAP<k,v>`           | <p>Associative array that maps keys to values.<br>No duplicate keys can exist in a map and each key can map to at most one value.<br>Type parameters <code>k</code> and <code>v</code> are required and they represent data type of the key elements and the value elements, respectively, throughout the map.</p><p>Order of keys within a <code>MAP</code> is not guaranteed, and may use one of <code>ARRAY</code> or <code>STRUCT</code> to guaranteed ordering within a set of queries.<br>For a given key, the associated value can be accessed using the <code>\[]</code> operator with the key.<br><br><strong>Example.</strong> In a relation DDL statement, the expression <code>manager MAP\<VARCHAR, VARCHAR></code> declares a column named <code>manager</code> with values of type map holding key value pairs of character string types. <code>manager\['HR']</code> is used to access the value associated with the key <code>HR</code> in a given value instance from this column.</p> |
| `STRUCT<fn ft, ...>` | <p>Strongly typed structured data type that represents an ordered collection of one or more <code>fields</code>.<br>A <code>field</code> consists of a name and a data type and captures a specific value in a given instance of struct.<br>Sequence of type parameter pair(s) <code>fn ft</code> represent name and data type for each and every field, in order.<br>A given field of a struct instance is accessed using the <code>-></code> operator with the field name.<br><br><strong>Example.</strong> In a relation DDL statement, the expression <code>address STRUCT\<city VARCHAR, zipcode VARCHAR></code> declares a column named <code>address</code> with values of type struct holding two fields of character string types, named <code>city</code> and <code>zipcode</code>. <code>address->city</code> is used to access the <code>city</code> field in a given value instance from this column.</p>                                                                                   |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.deltastream.io/reference/sql-syntax/data-types.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
