COMMENT ON 是一个用于定义、修改或删除对象注释的 DDL 命令。
COMMENT ON 在 PostgreSQL 7.0 中被添加。
支持函数
以下系统函数提供了提取对象注释的 SQL 级支持
变更历史
- PostgreSQL 11
- PostgreSQL 10
- PostgreSQL 9.6
COMMENT ON ACCESS METHOD已添加(提交 4f04b66f)
- PostgreSQL 9.5
- PostgreSQL 9.3
- PostgreSQL 9.1
- PostgreSQL 8.3
- PostgreSQL 8.2
- PostgreSQL 8.0
- PostgreSQL 7.3
- PostgreSQL 7.0
- 已添加(提交 7acc2377)
示例
为表添加注释
postgres=# COMMENT ON TABLE foo IS 'Store all the things';
COMMENT
postgres=# \dt+ foo
List of relations
Schema | Name | Type | Owner | Persistence | Access Method | Size | Description
--------+------+-------+----------+-------------+---------------+---------+----------------------
public | foo | table | postgres | permanent | heap | 0 bytes | Store all the things
(1 row)
修改表的注释
postgres=# COMMENT ON TABLE foo IS 'Store most of the things';
COMMENT
postgres=# \dt+ foo
List of relations
Schema | Name | Type | Owner | Persistence | Access Method | Size | Description
--------+------+-------+----------+-------------+---------------+---------+--------------------------
public | foo | table | postgres | permanent | heap | 0 bytes | Store most of the things
(1 row)
从表中删除注释
postgres=# COMMENT ON TABLE foo IS NULL;
COMMENT
postgres=# \dt+ foo
List of relations
Schema | Name | Type | Owner | Persistence | Access Method | Size | Description
--------+------+-------+----------+-------------+---------------+---------+-------------
public | foo | table | postgres | permanent | heap | 0 bytes |
(1 row)
参考资料
- PostgreSQL 文档: COMMENT
