# Data Types DataFusion uses Arrow, and thus the Arrow type system, for query execution. The SQL types from [sqlparser-rs](https://github.com/sqlparser-rs/sqlparser-rs/blob/main/src/ast/data_type.rs#L49) are mapped to [Arrow data types](https://docs.rs/arrow/latest/arrow/datatypes/enum.DataType.html) according to the following table. This mapping occurs when defining the schema in a `CREATE EXTERNAL TABLE` command or when performing a SQL `CAST` operation. For background on extension types and custom metadata, see the [Implementing User Defined Types and Custom Metadata in DataFusion] blog. [implementing user defined types and custom metadata in datafusion]: https://datafusion.apache.org/blog/2025/09/21/custom-types-using-metadata You can see the corresponding Arrow type for any SQL expression using the `arrow_typeof` function. For example: ```sql select arrow_typeof(interval '1 month'); +---------------------------------------------------------------------+ | arrow_typeof(IntervalMonthDayNano("79228162514264337593543950336")) | +---------------------------------------------------------------------+ | Interval(MonthDayNano) | +---------------------------------------------------------------------+ ``` You can cast a SQL expression to a specific Arrow type using the `arrow_cast` function For example, to cast the output of `now()` to a `Timestamp` with second precision: ```sql select arrow_cast(now(), 'Timestamp(s)') as "now()"; +---------------------+ | now() | +---------------------+ | 2025-10-24T20:02:45 | +---------------------+ ``` The older syntax still works as well: ```sql select arrow_cast(now(), 'Timestamp(Second, None)') as "now()"; +---------------------+ | now() | +---------------------+ | 2023-03-03T17:19:21 | +---------------------+ ``` ## Character Types | SQL DataType | Arrow DataType | | ------------------- | -------------- | | `CHAR` | `Utf8View` | | `VARCHAR` | `Utf8View` | | `TEXT` | `Utf8View` | | `STRING` | `Utf8View` | | `CHARACTER VARYING` | `Utf8View` | | `CHAR VARYING` | `Utf8View` | | `NVARCHAR` | `Utf8View` | By default, string types are mapped to `Utf8View`. This can be configured using the `datafusion.sql_parser.map_string_types_to_utf8view` setting. When set to `false`, string types are mapped to `Utf8` instead. Note that `CHAR`, `VARCHAR`, `STRING`, `CHARACTER VARYING`, `CHAR VARYING`, and `NVARCHAR` can optionally receive the maximum length (e.g., `VARCHAR(n)`). However, this limit is ignored. To raise an error when the length is passed, set `datafusion.sql_parser.support_varchar_with_length` to `false`. ## Numeric Types | SQL DataType | Arrow DataType | | ----------------------------------------------------------------------------- | :----------------------------- | | `TINYINT` | `Int8` | | `SMALLINT` or `INT2` | `Int16` | | `INT` or `INTEGER` or `INT4` | `Int32` | | `BIGINT` or `INT8` | `Int64` | | `TINYINT UNSIGNED` or `UTINYINT` | `UInt8` | | `SMALLINT UNSIGNED` or `INT2 UNSIGNED` or `USMALLINT` | `UInt16` | | `INT UNSIGNED` or `INTEGER UNSIGNED` or `INT4 UNSIGNED` | `UInt32` | | `BIGINT UNSIGNED` or `INT8 UNSIGNED` or `UBIGINT` | `UInt64` | | `FLOAT` or `FLOAT4` or `REAL` | `Float32` | | `DOUBLE` or `DOUBLE PRECISION` or `FLOAT8` | `Float64` | | `DECIMAL(precision, scale) or NUMERIC(precision, scale)` where precision ≤ 38 | `Decimal128(precision, scale)` | | `DECIMAL(precision, scale) or NUMERIC(precision, scale)` where precision > 38 | `Decimal256(precision, scale)` | The maximum supported precision for `DECIMAL` types is 76. ## Date/Time Types | SQL DataType | Arrow DataType | | ------------------------------------------------------------- | :--------------------------------------------------------- | | `DATE` | `Date32` | | `TIME` | `Time64(Nanosecond)` | | `TIMESTAMP`, `TIMESTAMP(p)`, `TIMESTAMP(p) WITHOUT TIME ZONE` | `Timestamp(unit, None)` | | `TIMESTAMPTZ(p)`, `TIMESTAMP(p) WITH TIME ZONE` | `Timestamp(unit, None)` by default — see the warning below | | `INTERVAL` | `Interval(MonthDayNano)` | :::{warning} `TIMESTAMPTZ` and `TIMESTAMP WITH TIME ZONE` do **not** give a timezone-aware type by default. The zone comes from the [`datafusion.execution.time_zone`] setting, and that setting is unset unless you set it. So `'2024-01-01T12:00:00Z'::timestamptz` gives `Timestamp(unit, None)` by default: the result type does not keep timezone metadata. An explicit offset in the input is still applied. DataFusion normalizes the value to UTC. For example, with the default setting, `'2024-01-01T12:00:00+07:00'::timestamptz` gives `2024-01-01T05:00:00`. It is not read as the local time `12:00:00`. This is a known bug. See [issue #25166]. PostgreSQL and DuckDB always give an aware type here, because their session time zone always has a value. Set `datafusion.execution.time_zone` to make these types aware. `'UTC'` is a good value. ::: `unit` comes from the optional precision `p` on the two `TIMESTAMP` rows. Use `0`, `3`, `6` or `9` for `Second`, `Millisecond`, `Microsecond` or `Nanosecond`. DataFusion rejects each other value of `p`. If you omit `p`, the unit is `Nanosecond`. The precision goes after `TIMESTAMPTZ`, but before `WITH TIME ZONE`: use `TIMESTAMPTZ(3)` or `TIMESTAMP(3) WITH TIME ZONE`. `DATE`, `TIME` and `INTERVAL` do not accept a precision. [`datafusion.execution.time_zone`]: ../configs.md [issue #25166]: https://github.com/apache/datafusion/issues/25166 ## Boolean Types | SQL DataType | Arrow DataType | | ------------------- | :------------- | | `BOOLEAN` or `BOOL` | `Boolean` | ## Binary Types | SQL DataType | Arrow DataType | | ------------ | :------------- | | `BYTEA` | `Binary` | | `BLOB` | `Binary` | | `BINARY` | `Binary` | | `VARBINARY` | `Binary` | | `BYTES` | `Binary` | You can create binary literals using a hex string literal such as `X'1234'` to create a `Binary` value of two bytes, `0x12` and `0x34`. ## Nested Types | SQL DataType | Arrow DataType | | --------------------------------- | :------------------------------ | | `ARRAY` or `T[]` | `List(T)` | | `T[n]` | `FixedSizeList(n x T)` | | `MAP(k, v)` | `Map(k, v)` | | `STRUCT<[c0] T0[, ..., [cn] Tn]>` | `Struct(c0: T0[, ..., cn: Tn])` | While columns defined with `STRUCT` require all rows to have the same schema, `MAP` imposes no such restriction. Also note that `STRUCT` can be declared without defining the field names. In that case, they will be set to `c0`, `c1`, ..., `cn`. ## Unsupported SQL Types | SQL Data Type | Arrow DataType | | ------------- | :------------------ | | `UUID` | _Not yet supported_ | | `CLOB` | _Not yet supported_ | | `REGCLASS` | _Not yet supported_ | | `CUSTOM` | _Not yet supported_ | | `ENUM` | _Not yet supported_ | | `SET` | _Not yet supported_ | | `DATETIME` | _Not yet supported_ |