Search Shortcut cmd + k | ctrl + k
- Installation
- What's New in the Docs for 2.0
- Documentation
- Getting Started
- Connect
- Data Import and Export
- Overview
- Data Sources
- CSV Files
- IO
- JSON Files
- Overview
- Creating JSON
- Loading JSON
- Writing JSON
- JSON Type
- JSON Functions
- Format Settings
- Installing and Loading
- SQL to / from JSON
- Caveats
- Multiple Files
- Parquet Files
- Partitioning
- Appender
- INSERT Statements
- Lakehouse Formats
- Client APIs
- Overview
- ADBC
- C
- Overview
- Startup
- Configuration
- Query
- Data Chunks
- Vectors
- Values
- Types
- Prepared Statements
- Appender
- Table Functions
- Replacement Scans
- API Reference
- C++
- CLI
- Overview
- Arguments
- Dot Commands
- Output Formats
- Agent Mode
- Editing
- Friendly CLI
- Safe Mode
- Autocomplete
- Syntax Highlighting
- Known Issues
- Go
- Overview
- Connect
- Import Data
- Run Queries
- Handle Results
- Write User Defined Functions
- Profile and Monitor
- Troubleshoot
- Java (JDBC)
- Overview
- Connect
- Import Data
- Run Queries
- Handle Results
- Write User Defined Functions
- Profile and Monitor
- Deploy as Native Image
- Troubleshoot
- Node.js (Neo)
- ODBC
- Python
- Overview
- Data Ingestion
- Appender
- Conversion between DuckDB and Python
- DB API
- Relational API
- Function API
- Types API
- Expression API
- Spark API
- API Reference
- Known Python Issues
- Migrating to 2.0
- R
- Rust
- Overview
- Connect
- Import Data
- Run Queries
- Handle Results
- Write User Defined Functions
- Profile and Monitor
- Troubleshoot
- Wasm
- Tertiary Clients
- SQL
- Introduction
- Statements
- Overview
- ANALYZE
- ALTER DATABASE
- ALTER TABLE
- ALTER VIEW
- ATTACH and DETACH
- CALL
- CHECKPOINT
- COMMENT ON
- CONNECT and DISCONNECT
- COPY
- CREATE INDEX
- CREATE MACRO
- CREATE SCHEMA
- CREATE SECRET
- CREATE SEQUENCE
- CREATE TABLE
- CREATE VIEW
- CREATE TRIGGER
- CREATE TYPE
- DELETE
- DESCRIBE
- DROP
- EXPORT and IMPORT DATABASE
- INSERT
- LOAD / INSTALL
- MERGE INTO
- PIVOT
- Profiling
- PREPARE, EXECUTE, and DEALLOCATE
- SELECT
- SET / RESET
- SET VARIABLE
- SHOW and SHOW DATABASES
- SUMMARIZE
- Transaction Management
- UNPIVOT
- UPDATE
- UPDATE EXTENSIONS
- USE
- VACUUM
- Query Syntax
- SELECT
- FROM and JOIN
- WHERE
- GROUP BY
- GROUPING SETS
- HAVING
- ORDER BY
- LIMIT and OFFSET
- SAMPLE
- Unnesting
- WITH
- WINDOW
- QUALIFY
- VALUES
- FILTER
- Set Operations
- Prepared Statements
- Data Types
- Overview
- Array
- Bitstring
- Blob
- Boolean
- Date
- Enum
- Geometry
- Interval
- List
- Literal Types
- Map
- NULL Values
- Numeric
- Struct
- Text
- Time
- Timestamp
- Time Zones
- Union
- Typecasting
- Variant
- Expressions
- Overview
- CASE Expression
- Casting
- Collations
- Comparisons
- IN Operator
- Logical Operators
- Star Expression
- Subqueries
- TRY
- Functions
- Overview
- Aggregate Functions
- Array Functions
- Bitstring Functions
- Blob Functions
- Date Format Functions
- Date Functions
- Date Part Functions
- Enum Functions
- Geometry Functions
- Interval Functions
- Lambda Functions
- List Functions
- Map Functions
- Nested Functions
- Numeric Functions
- Pattern Matching
- Regular Expressions
- Struct Functions
- Text Functions
- Time Functions
- Timestamp Functions
- Timestamp with Time Zone Functions
- Union Functions
- Utility Functions
- Variant Functions
- Window Functions
- Constraints
- Indexes
- Meta Queries
- DuckDB's SQL Dialect
- Overview
- Indexing
- Friendly SQL
- Keywords and Identifiers
- Order Preservation
- PostgreSQL Compatibility
- SQL Quirks
- PEG Parser
- Samples
- Configuration
- Extensions
- Overview
- Installing Extensions
- Advanced Installation Methods
- Distributing Extensions
- Extension Repositories
- Community Extensions
- Versioning of Extensions
- Troubleshooting of Extensions
- Core Extensions
- Overview
- AutoComplete
- Avro
- AWS
- Azure
- Delta
- DuckLake
- Encodings
- Excel
- Full Text Search
- httpfs (HTTP and S3)
- Overview
- HTTP(S) Support
- Hugging Face
- S3 API Support
- S3 and AWS Authentication
- Legacy Authentication Scheme for S3 API
- Iceberg
- ICU
- inet
- Lance
- Legacy Parser
- MotherDuck
- MySQL
- ODBC
- Quack
- PostgreSQL
- Sirius
- Spatial
- SQLite
- SQLSmith
- TPC-DS
- TPC-H
- UI
- Unity Catalog
- Vortex
- VSS
- Quack Remote Protocol
- Guides
- Overview
- Data Viewers
- Database Integration
- File Formats
- Overview
- CSV Import
- CSV Export
- Directly Reading Files
- Directly Reading DuckDB Databases
- Excel Import
- Excel Export
- JSON Import
- JSON Export
- Parquet Import
- Parquet Export
- Querying Parquet Files
- File Access with the file: Protocol
- Meta Queries
- Describe Table
- EXPLAIN: Inspect Query Plans
- EXPLAIN ANALYZE: Profile Queries
- List Tables
- Summarize
- DuckDB Environment
- Network and Cloud Storage
- Overview
- HTTP Parquet Import
- HTTP CSV Import
- S3 Parquet Import
- S3 Parquet Export
- S3 Iceberg Import
- S3 Express One
- GCS Import
- Cloudflare R2 Import
- DuckDB over HTTPS / S3
- Share a Views-Only Database
- Fastly Object Storage Import
- SeaweedFS Import
- Tigris Import
- ODBC
- Performance
- Overview
- Environment
- Import
- Schema
- Indexing
- Join Operations
- File Formats
- How to Tune Workloads
- My Workload Is Slow
- Out-of-Memory Issues
- Benchmarks
- Working with Huge Databases
- Python
- Installation
- Executing SQL
- Jupyter Notebooks
- marimo Notebooks
- SQL on Pandas
- Import from Pandas
- Export to Pandas
- Import from Numpy
- Export to Numpy
- SQL on Arrow
- Import from Arrow
- Export to Arrow
- Relational API on Pandas
- Multiple Python Threads
- Integration with Ibis
- Integration with Polars
- Integration with PyTorch
- Using fsspec Filesystems
- SQL Editors
- Beekeeper Studio SQL Editor
- DBeaver SQL IDE
- DBine SQL Editor
- LibreDB Studio SQL Editor
- VisuaLeaf SQL Editor
- SQL Features
- AsOf Join
- Full-Text Search
- Graph Queries
- query and query_table Functions
- Merge Statement for SCD Type 2
- Timestamp Issues
- Snippets
- Creating Synthetic Data
- Dutch Railway Datasets
- Sharing Macros
- Analyzing a Git Repository
- Importing Duckbox Tables
- Copying an In-Memory Database to a File
- Calculating a Database Checksum
- Troubleshooting
- Glossary of Terms
- Browsing Offline
- Operations Manual
- Overview
- Migrating to DuckDB v2.0
- Backup Extension Repositories
- DuckDB's Footprint
- Installing DuckDB
- Logging
- User Agents
- Securing DuckDB
- Non-Deterministic Behavior
- Limits
- DuckDB Docker Container
- Development
- Overview
- DuckDB Repositories
- Release Cycle
- Metrics
- Profiling
- Building DuckDB
- Overview
- Build Configuration
- Building Extensions
- Statically Linking Extensions
- Android
- Linux
- macOS
- Raspberry Pi
- Windows
- Python
- R
- Troubleshooting
- Unofficial and Unsupported Platforms
- Benchmark Suite
- Testing
- Overview
- sqllogictest Introduction
- Writing Tests
- Unit Tester Configuration
- Debugging
- Result Verification
- Persistent Testing
- Loops
- Multiple Connections
- Catch
- Internal Errors
- Internals
- Sitemap
- Live Demo
Variant Functions
This section describes functions that operate on the VARIANT type.
New Most
variant_*functions were introduced in DuckDB 2.0. Thevariant_extract,variant_normalizeandvariant_typeoffunctions were already available in DuckDB 1.5.
| Name | Description |
|---|---|
variant_typeof(v) |
Return the full type of a VARIANT value, including nested structure. |
variant_type(v) |
Return the top-level type category of a VARIANT value. |
variant_keys(v) |
Return the keys of a VARIANT object as a list. |
variant_extract(v, field) |
Extract a nested value by object field name or list index. Returns a VARIANT. |
variant_extract_string(v, field) |
Extract a nested value as a VARCHAR. |
variant_array_length(v) |
Return the number of elements in a VARIANT array. |
variant_exists(v, key) |
Return whether the given key exists in a VARIANT object. |
variant_contains(haystack, needle) |
Return whether the needle VARIANT is contained in the haystack VARIANT. |
variant_comparator(v) |
Return a binary sort key that orders a VARIANT value by the logical ordering of VARIANT values. |
variant_normalize(v) |
Return a canonical representation of a VARIANT value, so that values representing the same data share the same form. |
variant_group_object(key, value) |
Aggregate. Return a VARIANT object built from all key, value pairs in the group. |
variant_group_array(x) |
Aggregate. Collect all values of x into a VARIANT array. |
variant_typeof(v)
| Description | Return the full type of a VARIANT value, including nested structure. |
| Example | variant_typeof('{"a": 1}'::JSON::VARIANT) |
| Result | OBJECT(a) |
variant_type(v)
| Description | Return the top-level type category of a VARIANT value. |
| Example | variant_type('{"a": 1}'::JSON::VARIANT) |
| Result | OBJECT |
variant_keys(v)
| Description | Return the keys of a VARIANT object as a list. |
| Example | variant_keys('{"a": 1, "b": 2}'::JSON::VARIANT) |
| Result | [a, b] |
variant_extract(v, field)
| Description | Extract a nested value by object field name or list index. Returns a VARIANT. |
| Example | variant_extract('{"name": "Fry"}'::JSON::VARIANT, 'name') |
| Result | Fry |
variant_extract_string(v, field)
| Description | Extract a nested value as a VARCHAR. |
| Example | variant_extract_string('{"name": "Fry"}'::JSON::VARIANT, 'name') |
| Result | Fry |
variant_array_length(v)
| Description | Return the number of elements in a VARIANT array. |
| Example | variant_array_length('[1, 2, 3]'::JSON::VARIANT) |
| Result | 3 |
variant_exists(v, key)
| Description | Return whether the given key exists in a VARIANT object. |
| Example | variant_exists('{"a": 1}'::JSON::VARIANT, 'a') |
| Result | true |
variant_contains(haystack, needle)
| Description | Return whether the needle VARIANT is contained in the haystack VARIANT. |
| Example | variant_contains('{"user": {"id": 42}}'::JSON::VARIANT, '{"user": {"id": 42}}'::JSON::VARIANT) |
| Result | true |
variant_comparator(v)
| Description | Return a binary sort key (a BLOB) that orders a VARIANT value according to the logical ordering of VARIANT values. This is used internally so that VARIANTs compare and sort consistently with the corresponding native DuckDB types, rather than by their internal byte representation. |
| Example | variant_comparator({'a': 1, 'b': 2}::VARIANT) |
| Result | A BLOB sort key |
Values are ordered first by type bucket (for example, booleans before numbers, numbers before strings) and then by value within a bucket, so that sorting a VARIANT column matches the order of the underlying values:
SELECT i
FROM range(-2, 2) t(i)
ORDER BY i::VARIANT;
| i |
|---|
| -2 |
| -1 |
| 0 |
| 1 |
variant_normalize(v)
| Description | Return a canonical representation of a VARIANT value. Two VARIANT values that represent the same data normalize to the same result, regardless of how they were constructed or physically stored. This is useful when comparing or storing VARIANT values. |
| Example | variant_normalize({'b': [1, 2, 3], 'a': 42}::VARIANT) |
| Result | A normalized VARIANT |
variant_group_object(key, value)
| Description | Aggregate function. Returns a VARIANT object containing all key, value pairs in the group, where key is a VARCHAR and value is a VARIANT. A NULL key or a duplicate key raises an error. |
| Example | variant_group_object('duck', 'goose'::VARIANT) |
| Result | {'duck': goose} |
New The
variant_group_objectaggregate was added in DuckDB 2.0.
variant_group_array(x)
| Description | Collects all values of x into a VARIANT array, preserving order. Defined as a macro equivalent to list(x)::VARIANT, so it has aggregate semantics and also works as a window function. NULL values are kept as VARIANT nulls. |
| Example | variant_group_array(i) |
| Result | [0, 1, 2, 3] |
New The
variant_group_arrayfunction was added in DuckDB 2.0.
Example
The variant_* functions are useful for inspecting and filtering semi-structured data stored in a VARIANT column:
CREATE TABLE events (payload VARIANT);
INSERT INTO events
VALUES ('{"user": {"id": 42, "tags": ["a", "b"]}}'::JSON::VARIANT);
SELECT variant_type(payload), variant_keys(payload)
FROM events;
SELECT *
FROM events
WHERE variant_contains(payload, {'user': {'id': 42}}::VARIANT);
© 2026 DuckDB Foundation, Amsterdam NL