Skip to main content

Describe

Describing a Table

To view the schema of a table, use the DESCRIBE statement (or its aliases DESC and SHOW) followed by the table name.

CREATE TABLE tbl (i INTEGER PRIMARY KEY, j VARCHAR);
DESCRIBE tbl;
SHOW tbl; -- equivalent to DESCRIBE tbl;
column_namecolumn_typenullkeydefaultextra
iINTEGERNOPRINULLNULL
jVARCHARYESNULLNULLNULL

Describing a Query

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

DESCRIBE SELECT * FROM tbl;
column_namecolumn_typenullkeydefaultextra
iINTEGERYESNULLNULLNULL
jVARCHARYESNULLNULLNULL

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 as 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://${uri}/Star_Trek-Season_1.csv';
column_namecolumn_typenullkeydefaultextra
season_numBIGINTYESNULLNULLNULL
episode_numBIGINTYESNULLNULLNULL
aired_dateDATEYESNULLNULLNULL
cnt_kirk_hookupsBIGINTYESNULLNULLNULL
cnt_downed_redshirtsBIGINTYESNULLNULLNULL
bool_aliens_almost_took_over_planetBIGINTYESNULLNULLNULL
bool_aliens_almost_took_over_enterpriseBIGINTYESNULLNULLNULL
cnt_vulcan_nerve_pinchBIGINTYESNULLNULLNULL
cnt_warp_speed_ordersBIGINTYESNULLNULLNULL
highest_warp_speed_issuedBIGINTYESNULLNULLNULL
bool_hand_phasers_firedBIGINTYESNULLNULLNULL
bool_ship_phasers_firedBIGINTYESNULLNULLNULL
bool_ship_photon_torpedos_firedBIGINTYESNULLNULLNULL
cnt_transporter_paxBIGINTYESNULLNULLNULL
cnt_damn_it_jim_quoteBIGINTYESNULLNULLNULL
cnt_im_givin_her_all_shes_got_quoteBIGINTYESNULLNULLNULL
cnt_highly_illogical_quoteBIGINTYESNULLNULLNULL
bool_enterprise_saved_the_dayBIGINTYESNULLNULLNULL