Describe
描述表
要查看表的 schema,请使用 DESCRIBE 语句(或其别名 DESC、SHOW)并跟上表名。
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 |
描述查询
要查看查询结果的 schema,请在查询前加上 DESCRIBE。
DESCRIBE SELECT * FROM tbl;
| column_name | column_type | null | key | default | extra |
|---|---|---|---|---|---|
| i | INTEGER | YES | NULL | NULL | NULL |
| j | VARCHAR | YES | NULL | NULL | NULL |
注意二者有细微差异:与描述表的结果相比,可空性(null)与键信息(key)会丢失。
在子查询中使用 DESCRIBE
DESCRIBE 可作为子查询使用。这样可以根据描述结果创建表,例如:
CREATE TABLE tbl_description AS SELECT * FROM (DESCRIBE tbl);
描述远程表
可通过 httpfs 扩展并使用 DESCRIBE TABLE 语句描述远程表。例如:
DESCRIBE TABLE 'https://${uri}/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 |