DESCRIBE
使用 DESCRIBE
命令查看指定表、source、sink、视图或物化视图中的列。
DESCRIBE
是 SHOW COLUMNS
的快捷方式。
tip
DESCRIBE
还会列出表或物化视图的索引,而 SHOW COLUMNS
则不会。
句法
DESCRIBE relation_name;
参数
参数或子句 | 描述 |
---|---|
relation_name | 要列出其列的表、source、sink、视图或物化视图。 |
示例
准备工作
CREATE TABLE customers (
customer_id BIGINT PRIMARY KEY,
name VARCHAR,
email VARCHAR
);
COMMENT ON COLUMN customers.customer_id IS '每个用户的唯一标识符';
COMMENT ON COLUMN customers.name IS '用户的姓名';
COMMENT ON COLUMN customers.email IS '用户的电子邮件地址';
COMMENT ON TABLE customers IS '所有用户数据';
CREATE INDEX idx_customers_email ON customers(email);
创建表、列和索引并为其添加注释后,可以使用 DESCRIBE
命令查看所有结构信息。
输出
DESCRIBE customers;
| Name | Type | Is Hidden | Description |
| ------------------- | --------------------------------------------------------------------- | --------- | ----------------------------------- |
| customer_id | bigint | false | Unique identifier for each customer |
| name | character varying | false | Name of the customer |
| email | character varying | false | Email address of the customer |
| primary key | customer_id | | |
| distribution key | customer_id | | |
| idx_customers_email | index(email ASC, customer_id ASC) include(name) distributed by(email) | | |
| table description | customers | | All customer records |