Work with views
On the DuckDB engine, a view is stored in the AWS Glue Data Catalog and can read Hive tables and other views. Each time you query a view, Athena reads its definition from the AWS Glue Data Catalog and runs it with the credentials of the principal that runs the query.
Create, query, and drop views
The engine supports CREATE VIEW, CREATE OR REPLACE VIEW, DROP VIEW, DROP VIEW IF EXISTS, DESCRIBE, and SELECT on views. A view can read another view, including one in another database, and its definition can use a WITH clause, subqueries, joins, and aggregates.
The following examples use the Hive table from the tutorial.
CREATE VIEW duckdb_tutorial.east_sales AS SELECT order_id, customer, amount FROM duckdb_tutorial.sales_parquet WHERE region = 'east'
SELECT customer, sum(amount) AS revenue FROM duckdb_tutorial.east_sales GROUP BY ALL
DROP VIEW IF EXISTS duckdb_tutorial.east_sales
Views can be nested up to 8 levels deep. A query on a view that is nested more deeply fails, and the message names the deepest view.
List views
To list the views in a database, run SELECT table_name FROM information_schema.tables WHERE table_schema = '. The result also includes views created by other engines. You can also run database' AND table_type = 'VIEW'SHOW TABLES FROM , which lists tables and views together. Replace databasedatabase with the name of your database.
What a view can read
-
Hive tables and other views only. A view cannot read an Apache Iceberg table, an Amazon S3 Tables table, or a Delta Lake table.
CREATE VIEWover such a table fails, and Athena does not create the view. -
Tables that are not registered with Lake Formation. A view whose definition reads a table in a location registered with AWS Lake Formation fails, as a query on that table does. See Lake Formation tables.
-
No table functions. The
FROMclause of a view cannot call a table function such asread_parquet,range, orunnest. Scalar functions such asupper(name)are allowed. -
The AWS Glue Data Catalog of your own account. Views are created in, and can read from, the AWS Glue Data Catalog of your own account only.
When a query fails because of a table that a view reads, the error message names that view.
Views and other engines
Views created by Athena engine version 3 or by other engines cannot be queried, replaced, or dropped on DuckDB. Keep using them from an engine version 3 workgroup or from the engine that created them.
Views created on DuckDB are Hive-style views in the AWS Glue Data Catalog. Other engines are not blocked from querying them. However, those queries might fail, or return results that differ from DuckDB because the engines evaluate some SQL differently. Query these views only from DuckDB.
These views are not multi-dialect Data Catalog views, which several engines can read. You cannot create a multi-dialect view on DuckDB in this Preview.
Statements that are not supported
| Statement | What to do instead |
|---|---|
CREATE TEMP VIEW
|
Create the view in the AWS Glue Data Catalog, or use a WITH clause.
|
ALTER VIEW v RENAME TO w
|
Run CREATE VIEW w AS ... with the same query, then DROP VIEW v.
|
SHOW VIEWS, SHOW CREATE VIEW
|
Not supported in this Preview. To list views, see List views. Use DESCRIBE to see a view's columns.
|
duckdb_views(), information_schema.views, pg_catalog.pg_views
|
Not supported in this Preview. To list views, see List views. |
CREATE VIEW with ExecutionParameters
|
Write the values into the view's query. |
CREATE PROTECTED MULTI DIALECT VIEW
|
Not supported in this Preview. See Views and other engines. |
| Materialized views | Not supported in this Preview. |
A statement that is not supported fails when the query runs. The error message does not always say that the statement is not supported. For example, SHOW CREATE VIEW fails with a syntax error. For how to read errors, see How Athena reports errors.