Zum Inhalt springen

DESCRIBE

Eine Tabelle beschreiben

Um das Schema einer Tabelle anzuzeigen, verwenden Sie die Anweisung DESCRIBE (oder ihre Aliase DESC und SHOW) gefolgt vom Tabellennamen.

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

Eine Abfrage beschreiben

Um das Schema des Ergebnisses einer Abfrage anzuzeigen, stellen Sie der Abfrage DESCRIBE voran.

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

Beachten Sie die feinen Unterschiede: Im Vergleich zum Ergebnis beim Beschreiben einer Tabelle gehen die Nullability (null) und die Schlüsselinformationen (key) verloren.

DESCRIBE in einer Unterabfrage verwenden

DESCRIBE kann als Unterabfrage verwendet werden. So lässt sich beispielsweise eine Tabelle aus der Beschreibung erstellen:

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

Entfernte Tabellen beschreiben

Über die httpfs-Extension können entfernte Tabellen mit der Anweisung DESCRIBE TABLE beschrieben werden. Zum Beispiel:

DESCRIBE TABLE 'https://blobs.duckdb.org/data/Star_Trek-Season_1.csv';
column_name column_type null key default extra
season_num BIGINT YES NULL NULL NULL
episode_num BIGINT YES NULL NULL NULL
aired_date DATE YES NULL NULL NULL
cnt_kirk_hookups BIGINT YES NULL NULL NULL
cnt_downed_redshirts BIGINT YES NULL NULL NULL
bool_aliens_almost_took_over_planet BIGINT YES NULL NULL NULL
bool_aliens_almost_took_over_enterprise BIGINT YES NULL NULL NULL
cnt_vulcan_nerve_pinch BIGINT YES NULL NULL NULL
cnt_warp_speed_orders BIGINT YES NULL NULL NULL
highest_warp_speed_issued BIGINT YES NULL NULL NULL
bool_hand_phasers_fired BIGINT YES NULL NULL NULL
bool_ship_phasers_fired BIGINT YES NULL NULL NULL
bool_ship_photon_torpedos_fired BIGINT YES NULL NULL NULL
cnt_transporter_pax BIGINT YES NULL NULL NULL
cnt_damn_it_jim_quote BIGINT YES NULL NULL NULL
cnt_im_givin_her_all_shes_got_quote BIGINT YES NULL NULL NULL
cnt_highly_illogical_quote BIGINT YES NULL NULL NULL
bool_enterprise_saved_the_day BIGINT YES NULL NULL NULL