View a markdown version of this page

Functions and operators in DuckDB - Amazon Athena

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 placeholder with 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 location s3://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 NULL input. 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

! (factorial)

Returns the factorial of an integer.

Numeric

%

Returns the remainder of dividing one number by another.

Numeric

&

Returns the bitwise AND of two integers or two bitstrings.

Numeric

&&

Tests whether two lists have at least one element in common.

List and array

*

Multiplies two numbers, or multiplies an interval by a number.

Numeric

**

Raises a number to a power.

Numeric

+

Adds two numbers, or adds an interval or a number of days to a date or time value.

Numeric

-

Subtracts one value from another, or negates a number.

Numeric

->

Extracts a value from JSON at a path or an array position and returns it as JSON. It is the operator form of json_extract.

JSON

->>

Extracts a value from JSON at a path or an array position and returns it as text.

JSON

/

Divides one number by another and returns a fractional result.

Numeric

//

Divides one integer by another and drops the fractional part.

Numeric

<

Tests whether the first value is less than the second.

Comparison

<->

Returns the straight-line (Euclidean) distance between two equal-length lists of numbers that represent points. It is the operator form of list_distance.

List and array

<<

Shifts the bits of an integer or a bitstring to the left.

Numeric

<=

Tests whether the first value is less than or equal to the second.

Comparison

<=>

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 list_cosine_distance.

List and array

<>, !=

Tests whether two values are not equal.

Comparison

<@

Tests whether every element of a list is in a second list. It is the operator form of list_has_all with the two lists in the other order.

List and array

=, ==

Tests whether two values are equal.

Comparison

>

Tests whether the first value is greater than the second.

Comparison

>=

Tests whether the first value is greater than or equal to the second.

Comparison

>>

Shifts the bits of an integer or a bitstring to the right.

Numeric

@

Returns the absolute value of a number.

Numeric

@>

Tests whether a list contains every element of a second list. It is the operator form of list_has_all.

List and array

^

Raises a number to a power. It is an alias of the ** operator.

Numeric

^@

Tests whether a string begins with a given prefix.

String

|

Returns the bitwise OR of two integers or two bitstrings.

Numeric

||

Joins two strings, two lists, or two BLOB values into one value.

String

~

Inverts every bit of an integer or a bitstring, or tests whether a string matches a regular expression.

Numeric

AND

Returns true when both conditions are true.

Expressions

GLOB

Tests whether a string matches a file-name style pattern that uses the *, ?, and [] wildcards.

String

ILIKE

Tests whether a string matches a pattern that uses the % and _ wildcards, ignoring case.

String

IS DISTINCT FROM

Tests whether two values are different (IS DISTINCT FROM) or the same (IS NOT DISTINCT FROM), and treats two NULL values as the same.

Comparison

LIKE

Tests whether a string matches a pattern that uses the % and _ wildcards, with case-sensitive matching.

String

NOT

Returns true when the condition is false, and false when it is true.

Expressions

OR

Returns true when at least one of the conditions is true.

Expressions

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

CREATE MACRO, CREATE FUNCTION, DROP MACRO, and DROP FUNCTION

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 WITH clause.

CREATE TYPE

You cannot define a named type, such as an ENUM type, for later statements to use. To use an ENUM type, write the type in full where you use it, for example CAST('ok' AS ENUM('sad', 'ok', 'happy')).

CREATE SEQUENCE and the nextval, currval, and setval functions

You cannot use sequences, because nothing carries over from one query to the next. To number the rows of a result, use row_number() OVER (ORDER BY column).

CREATE TRIGGER

Tables in Athena do not have triggers.

CREATE INDEX and the ADD PRIMARY KEY and ADD UNIQUE actions of ALTER TABLE

Tables in Athena do not have indexes, primary keys, or unique constraints.

Temporary tables (CREATE TEMP TABLE)

Nothing carries over from one query to the next, so a temporary table cannot outlive the query that creates it. Use a WITH clause in the same query, or create a table in the AWS Glue Data Catalog with CREATE TABLE AS SELECT.

ALTER DATABASE

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 ALTER SCHEMA with SET (...) or RESET (...), for example ALTER SCHEMA sales_db SET (comment = 'Sales data').

CHECKPOINT and FORCE CHECKPOINT

Your data is in Amazon S3, not in a local database file, so there is nothing to checkpoint.

VACUUM

In open-source DuckDB, VACUUM works only on tables that the engine stores in its own database file. In DuckDB in Athena, VACUUM does not remove old snapshots or unused data files from your tables. To remove old snapshots of an Iceberg table, run VACUUM in an Athena engine version 3 workgroup.

EXPORT DATABASE and IMPORT DATABASE

You cannot write a whole database to files, or load one back from files. To copy a table, use CREATE TABLE AS SELECT.

COPY FROM DATABASE

You cannot copy all the tables of one database into another in one statement. To copy a table, use CREATE TABLE AS SELECT.

PIVOT without an IN list, or with a subquery as its IN list

DuckDB in Athena does not read the data to find the output columns of a PIVOT, so you must name the values to pivot on. List the values with IN, for example PIVOT sales_db.sales_parquet ON region IN ('east', 'west') USING sum(amount). The values cannot come from a subquery, such as IN (SELECT DISTINCT region FROM sales_db.sales_parquet).

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 (BEGIN, COMMIT, and ROLLBACK)

Each query is one statement, so you cannot group several statements into one transaction.

SET, RESET, USE, and SET VARIABLE

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 sales_db.sales_parquet.

PREPARE, EXECUTE, DEALLOCATE, and duckdb_prepared_statements

Each query runs on its own, so a later query cannot run a statement that an earlier query prepared.

PRAGMA statements

You cannot read or change engine options with PRAGMA. Use DESCRIBE to see a table's columns, and SHOW TABLES to list tables.

current_setting, duckdb_settings, duckdb_variables, and pg_settings

You cannot read engine settings or session variables in a query.

Profiling and metrics: enable_profiling, disable_profiling, duckdb_profiling_settings, duckdb_available_metrics, and duckdb_live_query_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 EXPLAIN.

Engine log functions: duckdb_logs, duckdb_logs_parsed, duckdb_log_contexts, parse_duckdb_log_message, write_log, truncate_duckdb_logs, enable_logging, and disable_logging

You cannot read, write, clear, or configure the engine's log in a query.

Extensions and attached databases

Function or feature Notes

INSTALL, LOAD, and UPDATE EXTENSIONS

You cannot add, load, or update extensions. The engine already loads the extensions that it includes.

duckdb_extensions and duckdb_extension_repositories

You cannot list the engine's extensions or extension repositories.

Open-source DuckDB extensions that the engine does not include, such as excel, fts, inet, vss, sqlite_scanner, postgres_scanner, mysql_scanner, tpch, tpcds, and azure

These extensions are not part of the engine, so you cannot use their functions, such as read_xlsx, sqlite_scan, and dbgen.

ATTACH and DETACH

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 sales_db.sales_parquet.

CONNECT and DISCONNECT

You cannot connect a query to another database or service.

SHOW DATABASES

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 SHOW SCHEMAS.

read_duckdb and DuckDB files

You cannot read a DuckDB file, in Amazon S3 or anywhere else.

DuckLake functions, such as ducklake_scan, ducklake_snapshots, ducklake_table_info, ducklake_table_changes, ducklake_expire_snapshots, and ducklake_merge_adjacent_files

You cannot attach a DuckLake catalog, so you cannot use any of the ducklake_ functions.

Delta Lake functions, such as delta_scan

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 read_csv, read_parquet, read_json, read_text, read_blob, and glob

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 s3:// path.

HTTP and HTTPS URLs

You cannot read files from web servers. Copy the file to Amazon S3 and read it with an s3:// path.

arrow_scan, arrow_scan_dumb, and scan_arrow_ipc

These functions read data that a client program holds in memory, which a query cannot reach.

Credentials and secrets

Function or feature Notes

CREATE SECRET and DROP SECRET

Athena reads your data with the credentials of the principal that runs the query, so you cannot create or drop stored credentials.

duckdb_secrets, which_secret, duckdb_secret_types, and duckdb_secret_type_parameters

You cannot list stored credentials, or the kinds of credentials that the engine accepts.

load_aws_credentials

You cannot load other AWS credentials in a query.

Introspection functions

Function or feature Notes

duckdb_views, information_schema.views, and pg_catalog.pg_views

You cannot list views, or get their SQL text, with this function or these views. To list views, see List views. Use DESCRIBE to see a view's columns.

duckdb_types and duckdb_keywords

You cannot list the engine's data types or SQL keywords.

duckdb_constraints, duckdb_indexes, duckdb_triggers, duckdb_sequences, and duckdb_dependencies

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 pg_class, pg_constraint, pg_index, pg_type, and sqlite_master; the information_schema views about constraints, such as table_constraints; and the format_type function

You cannot use these views and functions, because they depend on listing functions that you also cannot use, such as duckdb_indexes and duckdb_types.

pg_get_viewdef and pg_get_constraintdef

You cannot get the SQL text of a view or a constraint. Use DESCRIBE to see a view's columns.

pragma_table_info and pragma_show

You cannot use these table-function forms of PRAGMA. Use DESCRIBE to see a table's columns.

pragma_collations

You cannot use these table-function forms of PRAGMA. For more information about the collations that you can use with COLLATE, see Collations.

pragma_user_agent, pragma_platform, and nanoarrow_version

You cannot read the engine's user agent or platform, or the version of the nanoarrow library that the engine includes, in a query. To read the release line of open-source DuckDB that the engine is built from, use the version function.

Engine memory and storage: duckdb_memory, duckdb_eviction_queues, duckdb_external_file_cache, duckdb_temporary_files, pragma_database_size, pragma_storage_info, pragma_metadata_info, get_block_size, duckdb_approx_database_count, and duckdb_connection_count

You cannot read the engine's memory, cache, storage, or connection details in a query.

duckdb_dialects, duckdb_grammar_extensions, add_grammar_extension, remove_grammar_extension, and duckdb_optimizers

You cannot list or change the SQL dialect or the optimizer in a query.

duckdb_table_sample

Tables do not keep a stored sample of their rows. To read a random sample of rows, use USING SAMPLE.

test_all_types and test_vector_types

You cannot use the DuckDB test functions.

Other functions

Function or feature Notes

The histogram and histogram_values table functions

You cannot use the table-function forms. You can still use the histogram aggregate function. Call histogram(column) as an aggregate in the SELECT list.

query and query_table

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.

json_execute_serialized_sql and json_serialize_plan

You cannot run a statement from its JSON form, or get a query plan as JSON. To see a query plan, use EXPLAIN.

sleep_ms and pg_sleep

You cannot use functions that pause a query.

getenv

You cannot read environment variables in a query.

duckdb_format_sql and sql_tokenize

You cannot format or tokenize SQL text with these functions.

Iceberg functions

Function or feature Notes

iceberg_rollback_to_snapshot

You cannot roll an Iceberg table back to an earlier snapshot. To read an earlier snapshot, use a time travel query with AT (VERSION => snapshot_id).

iceberg_rewrite_data_files

You cannot rewrite the data files of an Iceberg table. To compact an Iceberg table, run OPTIMIZE in an Athena engine version 3 workgroup.

iceberg_expire_snapshots

You cannot expire the old snapshots of an Iceberg table. To remove old snapshots of an Iceberg table, run VACUUM in an Athena engine version 3 workgroup.

iceberg_load_table_response

You cannot get the raw response that the catalog returns for an Iceberg table. Use the Iceberg metadata functions, such as iceberg_metadata and iceberg_snapshots.

set_iceberg_schema_properties and remove_iceberg_schema_properties

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 ST_Area, ST_Distance, ST_Contains, ST_Intersects, ST_Within, ST_DWithin, ST_Point, ST_GeomFromText, ST_X, ST_Y, ST_Length, ST_Centroid, ST_Buffer, ST_Transform, and ST_Union

The spatial extension is not part of the engine, so you cannot use its functions.

duckdb_coordinate_systems

You cannot list the coordinate reference systems that the engine knows.

Calls to other services

Function or feature Notes

CloudFormation functions: cloudformation_create_stack, cloudformation_delete_stack, cloudformation_describe_stack, cloudformation_describe_stacks, and cloudformation_list_stacks

You cannot create, delete, or read CloudFormation stacks in a query.

Amazon S3 Tables functions: s3tables_create_table_bucket, s3tables_delete_table_bucket, s3tables_get_table_bucket, s3tables_namespaces, s3tables_table_bucket_tags, s3tables_table_buckets, and s3tables_tables

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, "s3tablescatalog/table-bucket".

External resource functions (create_external_resource, destroy_external_resource, register_external_resource, deregister_external_resource, register_external_resource_type, duckdb_external_resources, and duckdb_external_resource_types) and the statement form of these functions

You cannot use a query to create, register, or remove resources outside the query.