DESC
功能
您可以使用该语句进行如下操作:
语法
DESC[RIBE] { [[<catalog_name>.]<db_name>.]<table_name> [ALL] | FILES(files_loading_properties) }
参数说明
| 参数 | 必选 | 说明 | 
|---|---|---|
| catalog_name | 否 | Internal catalog 或 external catalog 的名称。 
 | 
| db_name | 否 | 数据库名称。 | 
| table_name | 是 | 表名称。 | 
| ALL | 否 | 
 | 
| FILES | 否 | FILES() 表函数。自 v3.3.4 起,您可以使用 DESC 和 FILES() 查看远端存储中文件的 Schema 信息。详细信息,参考 Function reference - FILES()。 | 
返回信息说明
+-----------+---------------+-------+------+------+-----+---------+-------+
| IndexName | IndexKeysType | Field | Type | Null | Key | Default | Extra |
+-----------+---------------+-------+------+------+-----+---------+-------+
返回信息中的参数说明:
| 参数 | 说明 | 
|---|---|
| IndexName | 表名。如查看外部数据源表结构,则不返回该参数。 | 
| IndexKeysType | 表的排序键类型。如查看外部数据源表结构,则不返回该参数。 | 
| Field | 列名。 | 
| Type | 列的数据型。 | 
| Null | 是否允许为 NULL。 
 | 
| Key | 是否为排序键。 
 | 
| Default | 数据类型的默认值。如该数据类型没有默认值,则返回 NULL。 | 
| Extra | 
 | 
说明:有关物化视图的展示,请参见示例二。
示例
示例一:查看 StarRocks 的 example_table 表结构信息。
DESC example_table;
或
DESC default_catalog.example_db.example_table;
返回信息如下:
+-------+---------------+------+-------+---------+-------+
| Field | Type          | Null | Key   | Default | Extra |
+-------+---------------+------+-------+---------+-------+
| k1    | TINYINT       | Yes  | true  | NULL    |       |
| k2    | DECIMAL(10,2) | Yes  | true  | 10.5    |       |
| k3    | CHAR(10)      | Yes  | false | NULL    |       |
| v1    | INT           | Yes  | false | NULL    |       |
+-------+---------------+------+-------+---------+-------+
示例二:查看 StarRocks 的 sales_records 表结构、排序键类型和物化视图。如下所示, sales_records 表只有一张物化视图 store_amt。
DESC db1.sales_records ALL;
+---------------+---------------+-----------+--------+------+-------+---------+-------+
| IndexName     | IndexKeysType | Field     | Type   | Null | Key   | Default | Extra |
+---------------+---------------+-----------+--------+------+-------+---------+-------+
| sales_records | DUP_KEYS      | record_id | INT    | Yes  | true  | NULL    |       |
|               |               | seller_id | INT    | Yes  | true  | NULL    |       |
|               |               | store_id  | INT    | Yes  | true  | NULL    |       |
|               |               | sale_date | DATE   | Yes  | false | NULL    | NONE  |
|               |               | sale_amt  | BIGINT | Yes  | false | NULL    | NONE  |
|               |               |           |        |      |       |         |       |
| store_amt     | AGG_KEYS      | store_id  | INT    | Yes  | true  | NULL    |       |
|               |               | sale_amt  | BIGINT | Yes  | false | NULL    | SUM   |
+---------------+---------------+-----------+--------+------+-------+---------+-------+
示例三:查看 Hive 中 hive_table 表结构。
DESC hive_catalog.hive_db.hive_table;
+-------+----------------+------+-------+---------+---------------+ 
| Field | Type           | Null | Key   | Default | Extra         | 
+-------+----------------+------+-------+---------+---------------+ 
| id    | INT            | Yes  | false | NULL    |               | 
| name  | VARCHAR(65533) | Yes  | false | NULL    |               | 
| date  | DATE           | Yes  | false | NULL    | partition key | 
+-------+----------------+------+-------+---------+---------------+
示例四:使用 DESC 查看 AWS S3 中 Parquet 文件 lineorder 的 Schema 信息。
说明
对于远端存储中的文件,DESC 仅返回以下三列:
Field、Type以及Null。
DESC FILES(
    "path" = "s3://inserttest/lineorder.parquet",
    "format" = "parquet",
    "aws.s3.access_key" = "AAAAAAAAAAAAAAAAAAAA",
    "aws.s3.secret_key" = "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
    "aws.s3.region" = "us-west-2"
);
+------------------+------------------+------+
| Field            | Type             | Null |
+------------------+------------------+------+
| lo_orderkey      | int              | YES  |
| lo_linenumber    | int              | YES  |
| lo_custkey       | int              | YES  |
| lo_partkey       | int              | YES  |
| lo_suppkey       | int              | YES  |
| lo_orderdate     | int              | YES  |
| lo_orderpriority | varchar(1048576) | YES  |
| lo_shippriority  | int              | YES  |
| lo_quantity      | int              | YES  |
| lo_extendedprice | int              | YES  |
| lo_ordtotalprice | int              | YES  |
| lo_discount      | int              | YES  |
| lo_revenue       | int              | YES  |
| lo_supplycost    | int              | YES  |
| lo_tax           | int              | YES  |
| lo_commitdate    | int              | YES  |
| lo_shipmode      | varchar(1048576) | YES  |
+------------------+------------------+------+
17 rows in set (0.05 sec)