Search Shortcut cmd + k | ctrl + k
Describe

Describing a Table

In order to view the schema of a table, use DESCRIBE or SHOW followed by the table name.

CREATE TABLE tbl (i INTEGER PRIMARY KEY, j VARCHAR);
DESCRIBE tbl;
SHOW tbl; -- equivalent to DESCRIBE tbl;
column_name column_type null key default extra
i INTEGER NO PRI NULL NULL
j VARCHAR YES NULL NULL NULL

Describing a Query

In order to view the schema of the result of a query, prepend DESCRIBE to a query.

DESCRIBE SELECT * FROM tbl;
column_name column_type null key default extra
i INTEGER YES NULL NULL NULL
j VARCHAR YES NULL NULL NULL

Note that there are subtle differences: compared to the result when describing a table, nullability (null) and key information (key) are lost.

Using DESCRIBE in a Subquery

DESCRIBE can be used a subquery. This allows creating a table from the description, for example:

CREATE TABLE tbl_description AS SELECT * FROM (DESCRIBE tbl);

Describing Remote Tables

It is possible to describe remote tables via the httpfs extension using the DESCRIBE TABLE statement. For example:

DESCRIBE TABLE 'https://blobs.duckdb.org/data/Star_Trek-Season_1.csv';
┌─────────────────────────────────────────┬─────────────┬─────────┬─────────┬─────────┬─────────┐
│               column_name               │ column_type │  null   │   key   │ default │  extra  │
│                 varchar                 │   varchar   │ varchar │ varchar │ varchar │ varchar │
├─────────────────────────────────────────┼─────────────┼─────────┼─────────┼─────────┼─────────┤
│ season_num                              │ BIGINT      │ YES     │         │         │         │
│ episode_num                             │ BIGINT      │ YES     │         │         │         │
│ aired_date                              │ DATE        │ YES     │         │         │         │
│ ...                                     │ ...         │ ...     │         │         │         │
├─────────────────────────────────────────┴─────────────┴─────────┴─────────┴─────────┴─────────┤
│ 18 rows                                                                             6 columns │
└───────────────────────────────────────────────────────────────────────────────────────────────┘
About this page

Last modified: 2024-03-02