Functions and operators in DuckDB
Use the topics in this section to look up the functions and operators that you can use in DuckDB queries. Each topic covers one category. It starts with a table that summarizes the category and links to the section for each function or operator. The larger categories put these sections on pages that group related functions, such as the regular expression functions of the string category.
How to read a function entry
Each function or operator section has some or all of the following parts, in this order.
- Syntax
-
This part shows the forms that you can use to call the function or operator. Replace each
placeholderwith a value or an expression. Parts in square brackets ([ ]) are optional. - Arguments
-
This part says what each placeholder stands for, including its data type.
- Return type
-
This part gives the data type of the result.
- Examples
-
This part has example queries, each followed by the result that DuckDB returns. Examples that read tables use a database named
sales_db. Examples that read files use the locations3://amzn-s3-demo-bucket/. To run these examples, replace these names with your own database and Amazon S3 location. - Considerations
-
This part describes behavior to keep in mind when you use the function, such as how it handles
NULLinput. It appears only when it applies. - Differences from Athena engine version 3
-
This part describes how the function behaves in Athena engine version 3, when that behavior is different. It appears only when it applies. For more information about moving queries from Athena engine version 3, see SQL differences from Athena v3.
Operator index
The following table lists each operator, with a link to the section that describes it.
| Operator | Description | Category |
|---|---|---|
|
Returns the factorial of an integer. |
|
Returns the remainder of dividing one number by another. |
||
Returns the bitwise AND of two integers or two bitstrings. |
||
Tests whether two lists have at least one element in common. |
||
Multiplies two numbers, or multiplies an interval by a number. |
||
Raises a number to a power. |
||
Adds two numbers, or adds an interval or a number of days to a date or time value. |
||
Subtracts one value from another, or negates a number. |
||
Extracts a value from JSON at a path or an array position and returns it as JSON. It is the operator form of |
||
Extracts a value from JSON at a path or an array position and returns it as text. |
||
Divides one number by another and returns a fractional result. |
||
Divides one integer by another and drops the fractional part. |
||
Tests whether the first value is less than the second. |
||
Returns the straight-line (Euclidean) distance between two equal-length lists of numbers that represent points. It is the operator form of |
||
Shifts the bits of an integer or a bitstring to the left. |
||
Tests whether the first value is less than or equal to the second. |
||
Returns 1 minus the cosine similarity of two equal-length lists of numbers, which measures how different their directions are. It is the operator form of |
||
Tests whether two values are not equal. |
||
Tests whether every element of a list is in a second list. It is the operator form of |
||
Tests whether two values are equal. |
||
Tests whether the first value is greater than the second. |
||
Tests whether the first value is greater than or equal to the second. |
||
Shifts the bits of an integer or a bitstring to the right. |
||
Returns the absolute value of a number. |
||
Tests whether a list contains every element of a second list. It is the operator form of |
||
Raises a number to a power. It is an alias of the |
||
Tests whether a string begins with a given prefix. |
||
Returns the bitwise OR of two integers or two bitstrings. |
||
Joins two strings, two lists, or two |
||
Inverts every bit of an integer or a bitstring, or tests whether a string matches a regular expression. |
||
Returns true when both conditions are true. |
||
Tests whether a string matches a file-name style pattern that uses the |
||
Tests whether a string matches a pattern that uses the |
||
Tests whether two values are different ( |
||
Tests whether a string matches a pattern that uses the |
||
Returns true when the condition is false, and false when it is true. |
||
Returns true when at least one of the conditions is true. |
Open-source DuckDB functions and features not available in Athena
DuckDB in Athena does not offer the following features of open-source DuckDB. Together, this list and the function reference topics cover the functions that this documentation describes. Before you rely on any other function, test it with DuckDB in Athena.
Statements
| Function or feature | Notes |
|---|---|
|
You cannot define, replace, or drop your own SQL macros or functions. Write the expression in the query, or put a shared subquery in a |
|
You cannot define a named type, such as an |
|
You cannot use sequences, because nothing carries over from one query to the next. To number the rows of a result, use |
|
Tables in Athena do not have triggers. |
|
Tables in Athena do not have indexes, primary keys, or unique constraints. |
Temporary tables ( |
Nothing carries over from one query to the next, so a temporary table cannot outlive the query that creates it. Use a |
|
In open-source DuckDB, this statement only renames an attached database. It does not apply to the databases in the AWS Glue Data Catalog. To set or remove the properties of a database, use |
|
Your data is in Amazon S3, not in a local database file, so there is nothing to checkpoint. |
|
In open-source DuckDB, |
|
You cannot write a whole database to files, or load one back from files. To copy a table, use |
|
You cannot copy all the tables of one database into another in one statement. To copy a table, use |
|
DuckDB in Athena does not read the data to find the output columns of a |
Session and configuration
| Function or feature | Notes |
|---|---|
Several statements in one query |
Each query must contain exactly one SQL statement. Submit each statement as its own query. |
Transactions ( |
Each query is one statement, so you cannot group several statements into one transaction. |
|
Engine settings are the same for every query, and you cannot change them. Nothing carries over from one query to the next. To choose the default database, set it in the query execution context, or qualify table names, for example |
|
Each query runs on its own, so a later query cannot run a statement that an earlier query prepared. |
|
You cannot read or change engine options with |
|
You cannot read engine settings or session variables in a query. |
Profiling and metrics: |
In a query, you cannot turn profiling on or off, or read the engine's metrics. To see how DuckDB plans a query, use |
Engine log functions: |
You cannot read, write, clear, or configure the engine's log in a query. |
Extensions and attached databases
| Function or feature | Notes |
|---|---|
|
You cannot add, load, or update extensions. The engine already loads the extensions that it includes. |
|
You cannot list the engine's extensions or extension repositories. |
Open-source DuckDB extensions that the engine does not include, such as |
These extensions are not part of the engine, so you cannot use their functions, such as |
|
A query reads the catalogs that Athena makes available to it, so you cannot attach other databases or detach these catalogs. Refer to tables in the AWS Glue Data Catalog by name, for example |
|
You cannot connect a query to another database or service. |
|
DuckDB in Athena does not support this statement, because in open-source DuckDB it lists the attached databases, not the databases in your catalog. To list the databases in a catalog, use |
|
You cannot read a DuckDB file, in Amazon S3 or anywhere else. |
DuckLake functions, such as |
You cannot attach a DuckLake catalog, so you cannot use any of the |
Delta Lake functions, such as |
DuckDB in Athena does not support Delta Lake tables. Query Delta Lake tables in an Athena engine version 3 workgroup. |
File and network access
| Function or feature | Notes |
|---|---|
Local file paths in |
The engine reads files only from Amazon S3. You cannot use paths on the machine that runs the query. Copy the file to Amazon S3 and read it with an |
HTTP and HTTPS URLs |
You cannot read files from web servers. Copy the file to Amazon S3 and read it with an |
|
These functions read data that a client program holds in memory, which a query cannot reach. |
Credentials and secrets
| Function or feature | Notes |
|---|---|
|
Athena reads your data with the credentials of the principal that runs the query, so you cannot create or drop stored credentials. |
|
You cannot list stored credentials, or the kinds of credentials that the engine accepts. |
|
You cannot load other AWS credentials in a query. |
Introspection functions
| Function or feature | Notes |
|---|---|
|
You cannot list views, or get their SQL text, with this function or these views. To list views, see List views. Use |
|
You cannot list the engine's data types or SQL keywords. |
|
Athena has no key constraints, indexes, triggers, or sequences for these functions to list, and you cannot list the dependencies between engine objects. |
PostgreSQL and SQLite catalog views, such as |
You cannot use these views and functions, because they depend on listing functions that you also cannot use, such as |
|
You cannot get the SQL text of a view or a constraint. Use |
|
You cannot use these table-function forms of |
|
You cannot use these table-function forms of |
|
You cannot read the engine's user agent or platform, or the version of the |
Engine memory and storage: |
You cannot read the engine's memory, cache, storage, or connection details in a query. |
|
You cannot list or change the SQL dialect or the optimizer in a query. |
|
Tables do not keep a stored sample of their rows. To read a random sample of rows, use |
|
You cannot use the DuckDB test functions. |
Other functions
| Function or feature | Notes |
|---|---|
The |
You cannot use the table-function forms. You can still use the |
|
A query cannot run SQL text, or read table names, that it builds while it runs. Write the full statement, with its table names, in the query. |
|
You cannot run a statement from its JSON form, or get a query plan as JSON. To see a query plan, use |
|
You cannot use functions that pause a query. |
|
You cannot read environment variables in a query. |
|
You cannot format or tokenize SQL text with these functions. |
Iceberg functions
| Function or feature | Notes |
|---|---|
|
You cannot roll an Iceberg table back to an earlier snapshot. To read an earlier snapshot, use a time travel query with |
|
You cannot rewrite the data files of an Iceberg table. To compact an Iceberg table, run |
|
You cannot expire the old snapshots of an Iceberg table. To remove old snapshots of an Iceberg table, run |
|
You cannot get the raw response that the catalog returns for an Iceberg table. Use the Iceberg metadata functions, such as |
|
You cannot set or remove the properties of a database with these functions. To read the properties of a database, use the iceberg_schema_properties function. |
Spatial functions
| Function or feature | Notes |
|---|---|
Spatial extension functions, such as |
The spatial extension is not part of the engine, so you cannot use its functions. |
|
You cannot list the coordinate reference systems that the engine knows. |
Calls to other services
| Function or feature | Notes |
|---|---|
CloudFormation functions: |
You cannot create, delete, or read CloudFormation stacks in a query. |
Amazon S3 Tables functions: |
You cannot create, delete, or read table buckets, or list their namespaces, tables, or tags, with these functions. To manage table buckets, use the Amazon S3 console or the Amazon S3 Tables API. To query the tables in a table bucket, use its catalog, |
External resource functions ( |
You cannot use a query to create, register, or remove resources outside the query. |