

# 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
<a name="athena-duckdb-views-create-query-and-drop-views"></a>

 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](duckdb-sql-reference.md#athena-duckdb-sql-tutorial-create-load-and-query-tables). 

```sql
CREATE VIEW duckdb_tutorial.east_sales AS
SELECT order_id, customer, amount
FROM duckdb_tutorial.sales_parquet
WHERE region = 'east'
```

```sql
SELECT customer, sum(amount) AS revenue
FROM duckdb_tutorial.east_sales
GROUP BY ALL
```

```sql
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
<a name="athena-duckdb-views-list-views"></a>

 To list the views in a database, run `SELECT table_name FROM information_schema.tables WHERE table_schema = '{{database}}' AND table_type = 'VIEW'`. The result also includes views created by other engines. You can also run `SHOW TABLES FROM {{database}}`, which lists tables and views together. Replace {{database}} with the name of your database. 

## What a view can read
<a name="athena-duckdb-views-what-a-view-can-read"></a>
+  **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 VIEW` over 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](duckdb-permissions.md#athena-duckdb-permissions-lake-formation-tables). 
+  **No table functions.** The `FROM` clause of a view cannot call a table function such as `read_parquet`, `range`, or `unnest`. Scalar functions such as `upper(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
<a name="athena-duckdb-views-views-created-by-other-engines"></a>

 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](views-glue.md), which several engines can read. You cannot create a multi-dialect view on DuckDB in this Preview. 

## Statements that are not supported
<a name="athena-duckdb-views-statements-that-are-not-supported"></a>


|  **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](#athena-duckdb-views-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](#athena-duckdb-views-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](#athena-duckdb-views-views-created-by-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](duckdb-troubleshooting.md#athena-duckdb-troubleshooting-how-athena-reports-errors). 