Data types in DuckDB
Every value in a DuckDB query has a data type. The data types are those of open-source DuckDB. This topic describes each family of types: the values that the types hold, how to write a literal value, and how query results show the values. Each section has an example that returns a literal value and the name of its type.
The example results in this topic show each value as the text that the GetQueryResults API returns for it. For a NULL value, the API returns no text, and the result tables show NULL.
The types that a table can store depend on its format. For example, Hive tables cannot store HUGEINT or INTERVAL values, and Iceberg tables cannot store UBIGINT or JSON values. For more information about the types that each table format can store, see Data types that each table format can store in SQL reference.
Type names and typeof
Type names are not case-sensitive, and many types have more than one name. For example, you can write INTEGER as INT, INT4, or SIGNED, and VARCHAR as STRING or TEXT. Each section of this topic lists the other names of its types.
To see the type of an expression, use the typeof function. It returns the name of the type as a VARCHAR value, in uppercase letters and with the parameters of the type, such as INTEGER, DECIMAL(2,1), or STRUCT(id INTEGER, note VARCHAR).
A NULL literal without a type has the type "NULL", which typeof returns with the double quotation marks. When you use such a literal in an expression, it takes the type that the expression needs, so NULL + 1 is an INTEGER. To give a NULL value a type, cast it, as in CAST(NULL AS INTEGER).
Syntax
typeof( expression )
Examples
The following SQL query returns the types of an integer literal, a string literal, and a NULL literal, and the types that the names INT8 and TEXT stand for.
SELECT typeof(42) AS integer_literal, typeof('abc') AS string_literal, typeof(NULL) AS null_literal, typeof(CAST(42 AS INT8)) AS int8_name, typeof(CAST('abc' AS TEXT)) AS text_name
The query returns the following result.
| integer_literal | string_literal | null_literal | int8_name | text_name |
|---|---|---|---|---|
|
|
|
|
|
Differences from Athena engine version 3
In Athena engine version 3, typeof returns type names in lowercase letters, and the type of a string literal includes its length, as in integer and varchar(3). In DuckDB, typeof returns uppercase names, and VARCHAR has no length. If your code compares the output of typeof with a type name, update the names that it expects.
Boolean type
The BOOLEAN type, also written BOOL or LOGICAL, holds the values true and false. As with every type, a BOOLEAN value can also be NULL, which stands for an unknown value. Write the literals as true and false. The literals are not case-sensitive.
When you cast a string to BOOLEAN, 'true', 't', 'yes', 'y', and '1' become true, and 'false', 'f', 'no', 'n', and '0' become false. The strings are not case-sensitive, and any other string makes the cast fail. When you cast a number, 0 becomes false, and any other number becomes true.
AND, OR, and NOT treat NULL as an unknown value. NULL AND false is false and NULL OR true is true, because the unknown value cannot change those results. The other combinations with NULL, such as NULL AND true, are NULL.
Query results show the values as true and false.
For more information about logical operators, see Logical operators AND, OR, and NOT.
Syntax
BOOLEAN
true | false
Examples
The following SQL query returns a BOOLEAN literal and its type, casts a string and a number to BOOLEAN, and combines NULL with false.
SELECT true AS value, typeof(true) AS type_name, CAST('f' AS BOOLEAN) AS from_text, CAST(0 AS BOOLEAN) AS from_zero, NULL AND false AS null_and_false
The query returns the following result.
| value | type_name | from_text | from_zero | null_and_false |
|---|---|---|---|---|
|
|
|
|
|
Integer types
The signed integer types hold whole numbers that can be negative, zero, or positive.
The unsigned integer types hold whole numbers from 0 to a maximum.
The following table lists the size and range of each integer type.
| Type | Size | Range |
|---|---|---|
|
1 byte |
-128 to 127 |
|
2 bytes |
-32768 to 32767 |
|
4 bytes |
-2147483648 to 2147483647 |
|
8 bytes |
-9223372036854775808 to 9223372036854775807 |
|
16 bytes |
-170141183460469231731687303715884105728 to 170141183460469231731687303715884105727 |
|
1 byte |
0 to 255 |
|
2 bytes |
0 to 65535 |
|
4 bytes |
0 to 4294967295 |
|
8 bytes |
0 to 18446744073709551615 |
|
16 bytes |
0 to 340282366920938463463374607431768211455 |
The types also have other names. You can write TINYINT as INT1, and SMALLINT as INT2, INT16, or SHORT. You can write INTEGER as INT, INT4, INT32, INTEGRAL, or SIGNED. You can write BIGINT as INT8, INT64, LONG, or OID, and HUGEINT as INT128. The unsigned types also have the names UINT8, UINT16, UINT32, UINT64, and UINT128, in order from UTINYINT to UHUGEINT.
Write an integer literal as digits, such as 42. The literal is an INTEGER when the value fits in that type, and otherwise a BIGINT or a HUGEINT. To get another integer type, cast the literal, as in CAST(255 AS UTINYINT) or 255::UTINYINT. A cast fails when the value is outside the range of the type, as in CAST(256 AS UTINYINT).
When an operator combines two integer types, the result has a type that holds the values of both, so a TINYINT plus a BIGINT is a BIGINT. If the result does not fit in that type, the query fails instead of returning a wider type. For example, 2147483647 + 1 fails, because both literals are INTEGER values. To avoid the error, cast one operand to a wider type, as in CAST(2147483647 AS BIGINT) + 1.
The sum function returns a HUGEINT for integer values, and the count function returns a BIGINT. Query results show integers as digits, without separators.
For more information about whole numbers that are outside the range of HUGEINT, see BIGNUM type.
Syntax
TINYINT | SMALLINT | INTEGER | BIGINT | HUGEINT
UTINYINT | USMALLINT | UINTEGER | UBIGINT | UHUGEINT
Examples
The following SQL query returns an integer literal and its type, and the types of two literals that are too large for INTEGER. It also returns a value cast to UTINYINT, with its type.
SELECT 42 AS int_value, typeof(42) AS int_type, typeof(3000000000) AS bigint_type, typeof(10000000000000000000) AS hugeint_type, CAST(255 AS UTINYINT) AS utinyint_value, typeof(CAST(255 AS UTINYINT)) AS utinyint_type
The query returns the following result.
| int_value | int_type | bigint_type | hugeint_type | utinyint_value | utinyint_type |
|---|---|---|---|---|---|
|
|
|
|
|
|
Considerations
INT8 is a name for the 8-byte BIGINT, but UINT8 is a name for the 1-byte UTINYINT.
Hive tables cannot store HUGEINT or UBIGINT values, and Iceberg tables cannot store UBIGINT or UHUGEINT values. Because sum of integers returns a HUGEINT, cast the result before you write it to a Hive table, as in CAST(sum(.x) AS BIGINT)
Differences from Athena engine version 3
In Athena engine version 3, sum of INTEGER values returns a BIGINT. DuckDB returns a HUGEINT. To get the Athena engine version 3 type, cast the result, as in CAST(sum(.x) AS BIGINT)
BIGNUM type
The BIGNUM type holds whole numbers of any size. Use it for values that are outside the range of HUGEINT. To make a BIGNUM value, cast an integer or a string of digits, as in CAST(42 AS BIGNUM) or CAST('123456789012345678901234567890' AS BIGNUM).
When you add or subtract two BIGNUM values, or a BIGNUM value and an integer, the result is an exact BIGNUM value. sum of BIGNUM values also returns a BIGNUM. Multiplication, division, and the // and % operators convert the values to DOUBLE, so their results are approximate. Because the values are DOUBLE, // keeps the fractional part of the quotient. When a BIGNUM value is too large for DOUBLE, which holds numbers up to about 1.8E308, these operations make the query fail.
Query results show a BIGNUM value as its digits, with a minus sign for a negative value.
Syntax
BIGNUM
CAST( value AS BIGNUM )
Examples
The following SQL query casts the largest HUGEINT value to BIGNUM. It returns the value, its type, the value plus 1, which is too large for HUGEINT, and the negated value.
SELECT b AS value, typeof(b) AS type_name, b + 1 AS plus_one, -b AS negated FROM ( SELECT CAST( 170141183460469231731687303715884105727 AS BIGNUM ) AS b ) AS t
The query returns the following result.
| value | type_name | plus_one | negated |
|---|---|---|---|
|
|
|
|
The following SQL query casts a string to BIGNUM, and returns the type of the value plus 1, minus 1, times 2, and divided by 2. Only addition and subtraction return a BIGNUM. The last column shows the value times 2, which is a DOUBLE.
SELECT typeof(x + 1) AS plus_type, typeof(x - 1) AS minus_type, typeof(x * 2) AS times_type, typeof(x / 2) AS divide_type, x * 2 AS times_two FROM (SELECT CAST('12' AS BIGNUM) AS x) AS t
The query returns the following result.
| plus_type | minus_type | times_type | divide_type | times_two |
|---|---|---|---|---|
|
|
|
|
|
Considerations
Iceberg tables cannot store BIGNUM values. To store one in an Iceberg table, cast it to a type that Iceberg tables can store, such as BIGINT when the value fits in that type, or VARCHAR.
Fixed-point decimal type
The DECIMAL type, also written NUMERIC or DEC, holds exact decimal numbers with up to 38 digits. It has two parameters: the precision, which is the total number of digits, and the scale, which is the number of digits after the decimal point. For example, DECIMAL(10,2) holds values from -99999999.99 to 99999999.99. A DECIMAL without a precision and scale is DECIMAL(18,3), and a DECIMAL with a precision but no scale has the scale 0.
A numeric literal with a decimal point and no exponent, such as 1.5, is a DECIMAL whose precision and scale fit its digits, here DECIMAL(2,1). Because such a literal is exact, 0.1 + 0.2 returns exactly 0.3.
When you cast a value that has more digits after the decimal point than the scale allows, DuckDB rounds the value. It rounds halves away from zero, so CAST(2.345 AS DECIMAL(10,2)) returns 2.35. A cast to an integer type rounds in the same way. If the value has too many digits before the decimal point, the cast fails.
Addition, subtraction, and multiplication of DECIMAL values return a DECIMAL. The / operator returns a DOUBLE. To divide decimals exactly, use the decimal_division function. For more information about exact division, see Exact decimal division.
Query results show a DECIMAL value with as many digits after the decimal point as its scale, including trailing zeros, so CAST(1.5 AS DECIMAL(10,2)) appears as 1.50.
Syntax
DECIMAL [ ( precision [, scale ] ) ]
In the syntax, replace each placeholder as follows:
precision-
The total number of digits, from 1 to 38. The default is 18.
scale-
The number of digits after the decimal point, from 0 to
precision. The default is 3 when you give neither parameter, and 0 when you give onlyprecision.
Examples
The following SQL query returns a decimal literal and its type. It also casts a value to DECIMAL without a precision and scale, which rounds the value to three decimal places, and returns the type of the result. The last two columns show that a value cast to two decimal places appears with a trailing zero, and that the sum of two decimal literals is exact.
SELECT 1.5 AS literal_value, typeof(1.5) AS literal_type, CAST(1.23456 AS DECIMAL) AS default_decimal, typeof(CAST(1.23456 AS DECIMAL)) AS default_type, CAST(1.5 AS DECIMAL(10, 2)) AS two_places, 0.1 + 0.2 AS exact_sum
The query returns the following result.
| literal_value | literal_type | default_decimal | default_type | two_places | exact_sum |
|---|---|---|---|---|---|
|
|
|
|
|
|
The following SQL query rounds a positive and a negative value to two decimal places. It casts the DECIMAL value 2.5 to INTEGER, which rounds away from zero to 3. It also returns the types of a product and a quotient.
SELECT CAST(2.345 AS DECIMAL(10, 2)) AS rounded, CAST(-2.345 AS DECIMAL(10, 2)) AS rounded_negative, CAST(2.5 AS INTEGER) AS decimal_to_integer, typeof(1.5 * 2) AS product_type, typeof(1.5 / 3) AS quotient_type
The query returns the following result.
| rounded | rounded_negative | decimal_to_integer | product_type | quotient_type |
|---|---|---|---|---|
|
|
|
|
|
Considerations
When you multiply two DECIMAL values that each have 18 or fewer digits, the result also has at most 18 digits, and the query fails if the product needs more. To avoid the error, cast one input to a wider type with the same scale, as in CAST(.a AS DECIMAL(38,4)) * b
Differences from Athena engine version 3
In Athena engine version 3, DECIMAL without a precision and scale is DECIMAL(38,0), so CAST(1.23456 AS DECIMAL) returns 1. In DuckDB, it is DECIMAL(18,3), and the same cast returns 1.235. To get the Athena engine version 3 result, write DECIMAL(38,0).
Athena engine version 3 reads a literal with a decimal point, such as 0.1, as a DOUBLE. In DuckDB, the same literal is an exact DECIMAL, so arithmetic on such literals is exact and has a DECIMAL result.
In Athena engine version 3, dividing two DECIMAL values returns a DECIMAL. In DuckDB, the / operator returns a DOUBLE, so CAST(1 AS DECIMAL(38,10)) / 3 * 3 returns 1.0 instead of 0.9999999999. For an exact result, use the decimal_division function.
Floating-point types
The FLOAT type, also written REAL or FLOAT4, holds 4-byte single-precision floating-point numbers. The DOUBLE type, also written FLOAT8 or DOUBLE PRECISION, holds 8-byte double-precision floating-point numbers. These types are approximate: many decimal fractions cannot be stored exactly, so 0.1e0 + 0.2e0 returns 0.30000000000000004. For exact values, such as amounts of money, use DECIMAL.
A numeric literal with an exponent, such as 1.5e0 or 2E3, is a DOUBLE. To get a FLOAT, cast the value, as in CAST(1.5 AS FLOAT).
Both types also hold three special values: NaN (not a number), positive infinity, and negative infinity. To write them, cast the strings 'NaN', 'Infinity', and '-Infinity', or the short forms 'nan', 'inf', and '-inf'. The strings are not case-sensitive. Unlike in the IEEE 754 standard, NaN is equal to itself and is greater than every other value, including positive infinity, so NaN values sort after all other numbers. To test for the special values, use isnan, isinf, and isfinite.
Query results show a floating-point value with the fewest digits that identify it, such as 1.5 or 0.30000000000000004. They show very large and very small values in exponent notation, such as 1e+20, and NaN and the infinities as nan, inf, and -inf.
Syntax
FLOAT | DOUBLE
Examples
The following SQL query returns a DOUBLE literal and its type, a value cast to FLOAT and its type, and a sum that shows that floating-point arithmetic is approximate.
SELECT 1.5e0 AS double_value, typeof(1.5e0) AS double_type, CAST(1.5 AS FLOAT) AS float_value, typeof(CAST(1.5 AS FLOAT)) AS float_type, 0.1e0 + 0.2e0 AS double_sum
The query returns the following result.
| double_value | double_type | float_value | float_type | double_sum |
|---|---|---|---|---|
|
|
|
|
|
The following SQL query makes NaN and the two infinities from strings, compares NaN with itself and with positive infinity, and returns a large DOUBLE literal.
SELECT CAST('NaN' AS DOUBLE) AS nan_value, CAST('Infinity' AS DOUBLE) AS positive_infinity, CAST('-Infinity' AS DOUBLE) AS negative_infinity, CAST( 'NaN' AS DOUBLE ) = CAST('NaN' AS DOUBLE) AS nan_equals_nan, CAST( 'NaN' AS DOUBLE ) > CAST('Infinity' AS DOUBLE) AS nan_is_largest, 1e20 AS large_value
The query returns the following result.
| nan_value | positive_infinity | negative_infinity | nan_equals_nan | nan_is_largest | large_value |
|---|---|---|---|---|---|
|
|
|
|
|
|
Considerations
A cast of a FLOAT or DOUBLE value to an integer type rounds halves to the nearest even number, so CAST(2.5e0 AS INTEGER) returns 2. A cast of a DECIMAL value rounds halves away from zero, so CAST(2.5 AS INTEGER) returns 3.
Differences from Athena engine version 3
A cast of a DOUBLE value to VARCHAR can return different text in the two engines. For example, CAST(1e20 AS VARCHAR) returns 1.0E20 in Athena engine version 3 and 1e+20 in DuckDB. A value such as 1.5e0 becomes 1.5 in both engines.
In Athena engine version 3, NaN is not greater than any value, so a filter such as skips the rows where x > 0 is NaN. In DuckDB, NaN is greater than every other value, so the same filter also returns those rows. To skip them, add xAND NOT isnan(.x)
String types
The VARCHAR type holds text of any length, in UTF-8. You can also write the type as STRING, TEXT, CHAR, BPCHAR, or NVARCHAR.
DuckDB accepts VARCHAR( and n)CHAR(, but it ignores the length: it does not cut values to n) characters, and it does not pad nCHAR( values with spaces. To shorten a string, use n)left(.string, n)
Write a string literal in single quotes, as in 'shipped'. To put a single quote in a string, write two single quotes, as in 'it''s'. Text in double quotes is an identifier, such as a column name, not a string.
Query results show a string without quotation marks. A string inside a list, struct, or map is also shown without quotation marks, unless it contains a character, such as a comma, that would make the value ambiguous. Then the string appears in single quotes, as in {delimiter=','}.
For more information about string functions and operators, see String functions and operators in DuckDB.
Syntax
VARCHAR
'text'
Examples
The following SQL query returns a string literal that contains a single quote, and the type of that literal. It also shows that a cast to VARCHAR(3) does not shorten a value, and that a cast to CHAR(3) does not pad a value with spaces.
SELECT 'it''s' AS value, typeof('it''s') AS type_name, CAST('abcdef' AS VARCHAR(3)) AS varchar_3, length(CAST('a' AS CHAR(3))) AS char_3_length
The query returns the following result.
| value | type_name | varchar_3 | char_3_length |
|---|---|---|---|
|
|
|
|
Differences from Athena engine version 3
In Athena engine version 3, CAST( cuts the value to x AS VARCHAR(n)) characters. DuckDB ignores the length, so use nleft( to shorten a string.x, n)
In Athena engine version 3, a CHAR( value is padded with spaces to n) characters. In DuckDB, nCHAR( is the same as n)VARCHAR, and values are not padded.
BLOB type
The BLOB type holds a sequence of bytes of any length, such as the contents of a binary file. You can also write the type as BYTEA, BINARY, or VARBINARY.
To write a BLOB literal, cast a string, as in '\xAA\xBB'::BLOB. In the string, \x followed by two hexadecimal digits stands for one byte, and any other ASCII character stands for its own byte. A backslash that does not start such a pair, or a character outside ASCII, makes the cast fail. You can also write a hexadecimal literal, as in X'4142', with two hexadecimal digits for each byte.
Query results show a BLOB value as text. Bytes that are letters, digits, and most other printable ASCII characters appear as those characters, and other bytes appear as \x followed by two hexadecimal digits, such as \xAA.
To convert text to the bytes of its UTF-8 encoding and back, use the encode function and the decode function. For more information about functions for BLOB values, see Blob and bitstring functions in DuckDB.
Syntax
BLOB
'bytes'::BLOB
X'hex_digits'
Examples
The following SQL query returns a BLOB literal and its type, a hexadecimal literal whose bytes are printable characters, and the number of bytes in the first value.
SELECT '\xAA\xBB'::BLOB AS value, typeof('\xAA\xBB'::BLOB) AS type_name, X'4142' AS hex_literal, octet_length('\xAA\xBB'::BLOB) AS byte_count
The query returns the following result.
| value | type_name | hex_literal | byte_count |
|---|---|---|---|
|
|
|
|
BIT type
The BIT type, also written BITSTRING, holds a sequence of bits of any length. To write a BIT literal, cast a string of 0 and 1 characters, as in '10110'::BIT. A string with any other character makes the cast fail.
Query results show a BIT value as a string of 0 and 1 characters.
For more information about bitstring functions, see Blob and bitstring functions in DuckDB.
Syntax
BIT
'bits'::BIT
Examples
The following SQL query returns a BIT literal and its type, its length in bits, and the number of bits that are set to 1.
SELECT '10110'::BIT AS value, typeof('10110'::BIT) AS type_name, bit_length('10110'::BIT) AS length_in_bits, bit_count('10110'::BIT) AS set_bits
The query returns the following result.
| value | type_name | length_in_bits | set_bits |
|---|---|---|---|
|
|
|
|
Considerations
Hive and Iceberg tables cannot store BIT values. To store a bitstring in a table, cast it to VARCHAR, as in CAST(.bits AS VARCHAR)
Date and time types
DATE holds a calendar date. TIME holds a time of day without a date, with microsecond precision, and TIME_NS holds a time of day with nanosecond precision. TIME WITH TIME ZONE, also written TIMETZ, holds a time of day together with a UTC offset, and keeps the offset that you write.
TIMESTAMP, also written DATETIME or TIMESTAMP_US, holds a date and a time of day without a time zone, with microsecond precision. For other precisions, use TIMESTAMP_S (seconds), TIMESTAMP_MS (milliseconds), or TIMESTAMP_NS (nanoseconds).
TIMESTAMP WITH TIME ZONE, also written TIMESTAMPTZ, holds an instant in time. You can write it with a UTC offset or with a time zone name, as in TIMESTAMPTZ '2026-11-18 10:30:00-08' or TIMESTAMPTZ '2026-11-18 10:30:00 America/Los_Angeles'. The value does not keep the offset or the zone. The session time zone is UTC, and you cannot change it, so query results show the instant in UTC, with the offset +00. TIMESTAMPTZ_NS holds an instant in the same way, with nanosecond precision.
INTERVAL holds a length of time as a number of months, a number of days, and a number of microseconds. The value keeps the three parts separately, so INTERVAL 36 HOUR is not changed to 1 day and 12 hours. Write an interval with a number and a unit, as in INTERVAL 90 MINUTE, or with a string of numbers and units, as in INTERVAL '2 hours 30 minutes'.
Write a literal of the other types with the type name and a string, as in DATE '2026-11-18', TIME '10:30:00', and TIMESTAMP '2026-11-18 10:30:00.123456'. Query results show the values in the same form, and leave out a fraction of a second that is zero, so TIMESTAMP '2026-11-18 10:30:00.000' appears as 2026-11-18 10:30:00. An interval appears as its years, months, and days, followed by its hours, minutes, and seconds, as in 1 year 2 months 3 days or 02:30:00.
For more information about date and time functions and operators, see Date and time functions and operators in DuckDB.
Syntax
DATE 'yyyy-mm-dd'
TIME 'hh:mm:ss[.fraction]'
TIME_NS 'hh:mm:ss[.fraction]'
TIMETZ 'hh:mm:ss[.fraction]offset'
TIMESTAMP 'yyyy-mm-dd hh:mm:ss[.fraction]'
TIMESTAMP_S 'yyyy-mm-dd hh:mm:ss[.fraction]'
TIMESTAMP_MS 'yyyy-mm-dd hh:mm:ss[.fraction]'
TIMESTAMP_NS 'yyyy-mm-dd hh:mm:ss[.fraction]'
TIMESTAMPTZ 'yyyy-mm-dd hh:mm:ss[.fraction]offset'
TIMESTAMPTZ 'yyyy-mm-dd hh:mm:ss[.fraction] time_zone'
TIMESTAMPTZ_NS 'yyyy-mm-dd hh:mm:ss[.fraction]offset'
INTERVAL number unit
INTERVAL 'number unit [ number unit ] [ ... ]'
In the syntax, replace each placeholder as follows:
fraction-
The fraction of a second.
TIMESTAMP_Skeeps no digits of the fraction, andTIMESTAMP_MSkeeps three.TIME_NS,TIMESTAMP_NS, andTIMESTAMPTZ_NSkeep up to nine digits, and the other types keep up to six. You can write more digits than the type keeps, and the query does not fail. This parameter is optional. offset-
A UTC offset, written right after the time, such as
-08,+05:30, or+00. time_zone-
A time zone name, written after a space, such as
America/Los_Angeles. unit-
A unit of time, such as
YEAR,MONTH,DAY,HOUR,MINUTE, orSECOND, in the singular or the plural.
Examples
The following SQL query returns a DATE, a TIME, and a TIMESTAMP literal, the type of the TIMESTAMP literal, and a timestamp whose fraction of a second is zero.
SELECT DATE '2026-11-18' AS date_value, TIME '10:30:00' AS time_value, TIMESTAMP '2026-11-18 10:30:00.123456' AS timestamp_value, typeof( TIMESTAMP '2026-11-18 10:30:00.123456' ) AS timestamp_type, TIMESTAMP '2026-11-18 10:30:00.000' AS zero_fraction
The query returns the following result.
| date_value | time_value | timestamp_value | timestamp_type | zero_fraction |
|---|---|---|---|---|
|
|
|
|
|
The following SQL query returns timestamps with second, millisecond, and nanosecond precision, and the type of the last one.
SELECT TIMESTAMP_S '2026-11-18 10:30:00' AS seconds_value, TIMESTAMP_MS '2026-11-18 10:30:00.123' AS milliseconds_value, TIMESTAMP_NS '2026-11-18 10:30:00.123456789' AS nanoseconds_value, typeof( TIMESTAMP_NS '2026-11-18 10:30:00.123456789' ) AS ns_type
The query returns the following result.
| seconds_value | milliseconds_value | nanoseconds_value | ns_type |
|---|---|---|---|
|
|
|
|
The following SQL query returns a TIMESTAMPTZ literal written with the offset -08, which the result shows in UTC, and its type. It also returns a TIMETZ literal, which keeps its offset, and an INTERVAL literal and its type.
SELECT TIMESTAMPTZ '2026-11-18 10:30:00-08' AS timestamptz_value, typeof( TIMESTAMPTZ '2026-11-18 10:30:00-08' ) AS timestamptz_type, TIMETZ '10:30:00-08' AS timetz_value, INTERVAL '2 hours 30 minutes' AS interval_value, typeof( INTERVAL '2 hours 30 minutes' ) AS interval_type
The query returns the following result.
| timestamptz_value | timestamptz_type | timetz_value | interval_value | interval_type |
|---|---|---|---|---|
|
|
|
|
|
The following SQL query returns a TIME_NS literal, a TIMESTAMPTZ_NS literal written with the offset -08, and their types. Both values keep nanoseconds. The result shows the TIMESTAMPTZ_NS value in UTC.
SELECT t AS time_ns_value, typeof(t) AS time_ns_type, tz AS timestamptz_ns_value, typeof(tz) AS timestamptz_ns_type FROM ( SELECT TIME_NS '10:30:00.123456789' AS t, TIMESTAMPTZ_NS '2026-11-18 10:30:00.123456789-08' AS tz ) AS v
The query returns the following result.
| time_ns_value | time_ns_type | timestamptz_ns_value | timestamptz_ns_type |
|---|---|---|---|
|
|
|
|
Considerations
Hive and Iceberg tables cannot store INTERVAL values. To store a length of time, convert it to a number first, for example to a number of seconds with date_part('epoch', .interval)
Differences from Athena engine version 3
In Athena engine version 3, a cast of a string to TIMESTAMP keeps milliseconds, so CAST('2026-11-18 10:30:00.123456' AS TIMESTAMP) returns 2026-11-18 10:30:00.123. DuckDB keeps microseconds and returns 2026-11-18 10:30:00.123456.
In Athena engine version 3, a timestamp with a time zone keeps the zone that you write, as in TIMESTAMP '2021-06-01 12:00:00 America/New_York'. In DuckDB, the same TIMESTAMP literal runs without an error but ignores the zone, and returns the TIMESTAMP value 2021-06-01 12:00:00. Write TIMESTAMPTZ '2021-06-01 12:00:00 America/New_York' instead. The value is stored as an instant, and query results show it in UTC.
In Athena engine version 3, a cast of a TIMESTAMP value with millisecond precision, such as a string cast to TIMESTAMP, to VARCHAR writes three digits of milliseconds, as in 2026-11-18 10:30:00.000. In DuckDB, the cast leaves out a fraction of a second that is zero, and otherwise writes up to six digits. To get the Athena engine version 3 text, use strftime(.ts, '%Y-%m-%d %H:%M:%S.%g')
Athena engine version 3 cannot query a Hive table that has a TIME or TIMESTAMP WITH TIME ZONE column. Do not use these types in Hive tables that other engines read. For more information about sharing tables, see Sharing tables with engine version 3 and other engines.
UUID type
The UUID type, also written GUID, holds a 128-bit universally unique identifier. To write a UUID literal, cast a string of 32 hexadecimal digits in groups of 8, 4, 4, 4, and 12 digits that are separated by hyphens. For example, write CAST('a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11' AS UUID). The digits can be uppercase or lowercase.
Query results show a UUID value in lowercase, with the hyphens.
To make a random UUID, use uuid or gen_random_uuid.
Syntax
UUID
CAST( 'uuid_text' AS UUID )
Examples
The following SQL query casts a string with uppercase digits to UUID, which the result shows in lowercase, and returns the type and the version number of the UUID.
SELECT CAST( 'A0EEBC99-9C0B-4EF8-BB6D-6BB9BD380A11' AS UUID ) AS value, typeof( CAST( 'A0EEBC99-9C0B-4EF8-BB6D-6BB9BD380A11' AS UUID ) ) AS type_name, uuid_extract_version( CAST( 'A0EEBC99-9C0B-4EF8-BB6D-6BB9BD380A11' AS UUID ) ) AS version
The query returns the following result.
| value | type_name | version |
|---|---|---|
|
|
|
Differences from Athena engine version 3
Athena engine version 3 cannot query a Hive table that has a UUID column. Do not use UUID columns in Hive tables that other engines read. To store a UUID in such a table, cast it to VARCHAR.
JSON type
The JSON type holds JSON text: an object, an array, a string, a number, true, false, or null. To make a JSON value, cast a string, as in CAST('{"id": 1}' AS JSON), or convert a SQL value with to_json. The cast checks that the text is valid JSON, and the query fails if it is not.
For more information about casts from text to JSON, including how they differ from Athena engine version 3, see CAST, TRY_CAST, and the :: operator.
Query results show a JSON value as its JSON text. The json and to_json functions write the text without spaces, as in {"id":1}.
The JSON functions also accept JSON text as a VARCHAR value. For more information about JSON functions and operators, see JSON functions and operators in DuckDB.
Syntax
JSON
CAST( 'json_text' AS JSON )
Examples
The following SQL query casts a string to JSON and returns its type, writes the same text without spaces with json, and converts a struct to JSON with to_json.
SELECT CAST( '{"id": 1, "tags": ["a", "b"]}' AS JSON ) AS value, typeof( CAST('{"id": 1, "tags": ["a", "b"]}' AS JSON) ) AS type_name, json('{"id": 1, "tags": ["a", "b"]}') AS minified, to_json({'id': 1, 'note': 'shipped'}) AS from_struct
The query returns the following result.
| value | type_name | minified | from_struct |
|---|---|---|---|
|
|
|
|
Considerations
Iceberg tables cannot store JSON values. To store JSON in an Iceberg table, cast it to VARCHAR.
Differences from Athena engine version 3
When DuckDB converts a DECIMAL whose precision is 15 or less to JSON, it writes the value as a DOUBLE, so trailing zeros are lost: 1.5000 becomes 1.5. A DECIMAL whose precision is 16 or more keeps its digits. Athena engine version 3 keeps the zeros. For more information about decimals in JSON, see Decimals in JSON.
LIST and ARRAY types
A LIST holds any number of values that all have the same type. Write the type as the element type followed by empty brackets, such as INTEGER[], and write a list literal in square brackets, such as [1, 2, 3]. ARRAY[1, 2, 3] and list_value(1, 2, 3) also make lists, not fixed-size ARRAY values. In a literal whose elements have different types, the elements are converted to a common type, and the query fails if there is none.
An ARRAY holds a fixed number of values, and the number is part of its type, such as INTEGER[3]. To make one, cast a list, as in CAST([1, 2, 3] AS INTEGER[3]). The cast fails if the list has a different number of elements.
Positions start at 1. returns the first element, list[1] returns the last element, and a position that does not exist, such as 0, returns list[-1]NULL. To get a slice, write , which includes both ends.list[start:end]
Query results show a LIST and an ARRAY the same way, as the elements in square brackets, such as [1, 2, 3]. For more information about how string elements appear, see String types.
For more information about list indexes and slices, including how they differ from Athena engine version 3, see List literals, indexes, and slices. For more information about list and array functions, see List and array functions and operators in DuckDB.
Syntax
element_type[]
element_type[n]
[ value [, ...] ]
Examples
The following SQL query returns a list literal and its type, and a list cast to an ARRAY of two elements with its type. It also returns the first element of a list, and the result for position 0 of the same list. That result is NULL, because the list has no element at that position.
SELECT [1, 2, 3] AS list_value, typeof([1, 2, 3]) AS list_type, CAST([1, 2] AS INTEGER[2]) AS array_value, typeof(CAST([1, 2] AS INTEGER[2])) AS array_type, ['a', 'b', 'c'][1] AS first_element, ['a', 'b', 'c'][0] AS position_zero
The query returns the following result.
| list_value | list_type | array_value | array_type | first_element | position_zero |
|---|---|---|---|---|---|
|
|
|
|
|
|
Considerations
Iceberg tables cannot store ARRAY values. To store one, cast it to a list first, as in CAST(.vector AS DOUBLE[])
Differences from Athena engine version 3
In Athena engine version 3, you write a list type as ARRAY(INTEGER). In DuckDB, write INTEGER[].
STRUCT type
A STRUCT holds a fixed set of named fields, and each field has its own type, as in STRUCT(id INTEGER, note VARCHAR). You can also write the type as ROW(id INTEGER, note VARCHAR). Write a struct literal in curly braces, with each field name followed by a colon and the value, as in {'id': 1, 'note': 'shipped'}. You can also build a struct with struct_pack(id := 1, note := 'shipped').
To read a field, use dot notation, as in , or a subscript with the field name, as in s.note.s['note']
The row function, as in row(1, 'shipped'), and two or more values in parentheses, as in (1, 'shipped'), make a struct whose fields have no names. For this type, typeof returns TUPLE with the field types, as in TUPLE(INTEGER, VARCHAR). To give the fields names, cast the value to a STRUCT type.
Query results show a struct in curly braces, with each field name in single quotes, followed by a colon and the value, as in {'id': 1, 'note': shipped}. They show a struct without field names as its values in parentheses, as in (1, shipped).
For more information about struct literals and field access, see Struct literals and field access. For more information about struct functions, see Struct, map, and union functions in DuckDB.
Syntax
STRUCT( name type [, ...] )
{ 'name': value [, ...] }
Examples
The following SQL query returns a struct literal and its type, reads one field with dot notation, and returns a struct without field names and its type.
SELECT {'id': 1, 'note': 'shipped'} AS value, typeof({'id': 1, 'note': 'shipped'}) AS type_name, {'id': 1, 'note': 'shipped'}.note AS note_field, row(1, 'shipped') AS unnamed_value, typeof(row(1, 'shipped')) AS unnamed_type
The query returns the following result.
| value | type_name | note_field | unnamed_value | unnamed_type |
|---|---|---|---|---|
|
|
|
|
|
Considerations
Iceberg tables cannot store structs without field names. To store one, cast it to a STRUCT type with field names.
MAP type
A MAP holds key-value pairs, as in MAP(VARCHAR, INTEGER). All keys have one type, and all values have one type. Keys must be unique and cannot be NULL, and a map with a duplicate or NULL key makes the query fail. Values can be NULL. A map keeps its entries in the order in which you add them.
Write a map literal with the MAP keyword and curly braces, as in MAP {'a': 1, 'b': 2}. You can also build a map from a list of keys and a list of values, as in map(['a', 'b'], [1, 2]). To read a value, use a subscript with the key, as in . A key that the map does not have returns m['a']NULL.
Query results show a map as pairs in curly braces, as in key=value{a=1, b=2}.
For more information about map functions, see Struct, map, and union functions in DuckDB.
Syntax
MAP( key_type, value_type )
MAP { key: value [, ...] }
Examples
The following SQL query returns a map literal and its type, the value for the key 'b', and the result for a key that the map does not have.
SELECT m AS value, typeof(m) AS type_name, m['b'] AS b_value, m['z'] AS missing_key FROM (SELECT MAP {'a': 1, 'b': 2} AS m) AS t
The query returns the following result.
| value | type_name | b_value | missing_key |
|---|---|---|---|
|
|
|
|
Differences from Athena engine version 3
In Athena engine version 3, element_at( returns the value for the key. In DuckDB, m, key)element_at returns a list that holds the value, or an empty list when the map does not have the key. To get the value, use .m[key]
UNION type
A UNION value holds one value from a fixed set of members. The UNION type is not related to the UNION set operator, which combines the rows of two queries. Each member has a tag name and a type, as in UNION(num INTEGER, str VARCHAR). To make a union value, cast a value to a UNION type. The cast chooses the member whose type is the type of the value. You can also use union_value(, which makes a union type with that one member.tag := value)
To read the tag of the member that a value holds, use the union_tag function. To read the value of a member, use the union_extract function, which returns NULL when the value holds a different member.
Query results show a union as the value of the member that it holds, as in 42.
For more information about union functions, see Struct, map, and union functions in DuckDB.
Syntax
UNION( tag type [, ...] )
union_value( tag := value )
Examples
The following SQL query casts an integer and a string to the same UNION type, and returns each value, its type, and the tag of the member that it holds.
SELECT u AS value, typeof(u) AS type_name, CAST(union_tag(u) AS VARCHAR) AS tag FROM (VALUES (1, CAST(42 AS UNION(num INTEGER, str VARCHAR))), ( 2, CAST( 'forty-two' AS UNION( num INTEGER, str VARCHAR ) ) ) ) AS t(id, u) ORDER BY id
The query returns the following results.
| value | type_name | tag |
|---|---|---|
|
|
|
|
|
|
Considerations
The union_tag function returns an ENUM value, and a query cannot return an ENUM value in its results. Cast the tag to VARCHAR, as in CAST(union_tag(.u) AS VARCHAR)
Hive and Iceberg tables cannot store UNION values.
ENUM type
An ENUM type holds one value from a fixed list of strings, as in ENUM('sad', 'ok', 'happy'). Write the type in full where you use it, as in CAST('ok' AS ENUM('sad', 'ok', 'happy')). A string that is not in the list makes the cast fail, and TRY_CAST returns NULL for it.
The values are ordered as they appear in the type. Sorting, min, max, and comparisons between two values of the same ENUM type use that order, so 'happy' sorts after 'ok'. A comparison between an ENUM value and a string literal compares the text instead. The enum_code function returns the position of a value in the list, starting at 0.
A query cannot return an ENUM value in its results. Cast the value to VARCHAR, as in CAST(, and the result shows the string.mood AS VARCHAR)
Syntax
ENUM( 'value' [, ...] )
Examples
The following SQL query casts a string to an ENUM type and returns the value cast back to VARCHAR, its type, and its position. The last column compares the value with a string literal, which compares the text: 'ok' sorts after 'happy' as text, although it comes before 'happy' in the list.
SELECT CAST(m AS VARCHAR) AS value, typeof(m) AS type_name, enum_code(m) AS position, m < 'happy' AS text_comparison FROM ( SELECT CAST('ok' AS ENUM('sad', 'ok', 'happy')) AS m ) AS t
The query returns the following result.
| value | type_name | position | text_comparison |
|---|---|---|---|
|
|
|
|
The following SQL query sorts strings by their position in an ENUM type, not in alphabetical order.
SELECT m AS mood, enum_code( CAST(m AS ENUM('sad', 'ok', 'happy')) ) AS position FROM (VALUES ('happy'), ('sad'), ('ok')) AS t(m) ORDER BY CAST(m AS ENUM('sad', 'ok', 'happy'))
The query returns the following results.
| mood | position |
|---|---|
|
|
|
|
|
|
Considerations
CREATE TYPE is not available, so you cannot give an ENUM type a name.
Hive tables cannot store ENUM values. To store one, cast it to VARCHAR.
VARIANT type
A VARIANT value holds a value of any type together with that type. This means that one VARIANT column can hold an integer in one row, a string in another, and a struct in a third. To make a VARIANT value, cast a value, as in CAST(42 AS VARIANT) or {'a': 1}::VARIANT.
For these values, typeof returns VARIANT. To see the type of the value that a VARIANT holds, use the variant_typeof function. It returns its own type names, such as INT32 for an INTEGER and VARCHAR for a string. For a list of two elements, it returns ARRAY(2), and for a struct with the fields a and b, it returns OBJECT(a, b). To get the value back as a SQL type, cast it, as in CAST(.v AS INTEGER)
A query result can't contain a VARIANT value. To return one, cast it to JSON or VARCHAR, or to the type of the value that it holds. To cast a VARIANT column named v to JSON while returning the other columns unchanged, use SELECT * REPLACE (. A v::JSON AS v)VARIANT value cast to VARCHAR shows its value in the same form as the other types, as in {'a': 1, 'b': [1, 2]}.
For more information about functions for VARIANT values, see Utility functions in DuckDB.
Syntax
VARIANT
CAST( expression AS VARIANT )
Examples
The following SQL query casts a struct to VARIANT, and returns the value cast to VARCHAR, its type, and the type of the value that it holds.
SELECT CAST(v AS VARCHAR) AS value, typeof(v) AS type_name, variant_typeof(v) AS held_type FROM ( SELECT CAST({'a': 1, 'b': [1, 2]} AS VARIANT) AS v ) AS t
The query returns the following result.
| value | type_name | held_type |
|---|---|---|
|
|
|
The following SQL query puts an integer, a string, and a list in one VARIANT column, and returns each value and the type of the value that it holds.
SELECT CAST(v AS VARCHAR) AS value, variant_typeof(v) AS held_type FROM (VALUES (1, CAST(42 AS VARIANT)), (2, CAST('text' AS VARIANT)), (3, CAST([1, 2] AS VARIANT)) ) AS t(id, v) ORDER BY id
The query returns the following results.
| value | held_type |
|---|---|
|
|
|
|
|
|
Considerations
Iceberg tables can store VARIANT values only in format version 3, and you cannot write nested VARIANT values to an Iceberg table.
Differences from Athena engine version 3
Athena engine version 3 cannot query a Hive table that has a VARIANT column. Do not use VARIANT columns in Hive tables that other engines read.
Implicit and explicit casts
To convert a value to another type, use CAST(, or the expression AS type):: operator, as in . If the value cannot be converted, the query fails. expression::typeTRY_CAST takes the same arguments as CAST, and returns NULL instead of failing. For more information about explicit casts, including how they round numbers and read strings, see CAST, TRY_CAST, and the :: operator.
DuckDB also converts values for you in some expressions. When an operator combines two numeric types, it converts one operand to a type that holds both, so an INTEGER plus a DOUBLE is a DOUBLE. A string literal is converted to the type that the expression needs, so DATE '2026-11-18' = '2026-11-18' is true. In arithmetic, the conversion can fail. For example, 1 + '1' fails, because + can add an integer to an integer or to a date. To avoid the error, cast the string, as in 1 + CAST('1' AS INTEGER). The || operator converts a value of another type to VARCHAR, so 1 || 'x' returns 1x.
A VARCHAR value that comes from a column or from an expression is not converted for you in arithmetic or in function arguments. For example, if is a sVARCHAR column, fails, so write s + 1CAST(. In the same way, a function that takes a string does not convert a number, so s AS INTEGER) + 1length(123) fails, and length(CAST(123 AS VARCHAR)) works.
Syntax
CAST( expression AS type )
expression::type
TRY_CAST( expression AS type )
Examples
The following SQL query casts a string to INTEGER with CAST and with ::. It uses TRY_CAST on a string that is not a number, which returns NULL, and casts the DOUBLE value 2.5e0 to INTEGER, which rounds to the even number 2. It also returns the type of an INTEGER plus a DOUBLE, and compares a DATE with a string literal.
SELECT CAST('42' AS INTEGER) + 1 AS cast_function, '42'::INTEGER + 1 AS cast_operator, TRY_CAST('forty-two' AS INTEGER) AS try_cast_result, CAST(2.5e0 AS INTEGER) AS double_to_integer, typeof(1 + 1.5e0) AS implicit_type, DATE '2026-11-18' = '2026-11-18' AS literal_compare
The query returns the following result.
| cast_function | cast_operator | try_cast_result | double_to_integer | implicit_type | literal_compare |
|---|---|---|---|---|---|
|
|
|
|
|
|
Differences from Athena engine version 3
Athena engine version 3 does not compare a DATE with a string literal, so DATE '2026-11-18' = '2026-11-18' fails. DuckDB converts the string literal, and the comparison succeeds.
Athena engine version 3 does not compare a number with a string literal, so 1 = '1' fails. DuckDB converts the string literal and returns true.
In Athena engine version 3, the || operator needs string operands, so 1 || 'x' fails. DuckDB converts the number to VARCHAR and returns 1x.