如何在重命名 table 名称后更改对列的注释?

How to alter comments on columns after renaming table name?

我正在使用 flyway 来处理我的数据库。 我通过以下方式更改了 table 名称:

 alter table tablename rename to table_name; 

如何更改我当前对所有栏的所有评论? 我应该删除它们并重新创建,还是有一个特定的 alter comment sql 命令可以在一行中执行此操作? 或者他们会相应地适应?

您不必 ALTER 发表评论。只需使用

COMMENT ON table_name.colname IS '...';

设置新评论。这将自动覆盖旧评论。

评论未被 ALTERed 或 DROPped。要删除评论,请使用 COMMENT ON.

将其设置为 NULL

评论是 "moved" table 重命名:

# select c.relname table_name, pg_catalog.obj_description(c.oid) as comment 
from pg_catalog.pg_class c where c.relname = 'old';
 table_name |   comment   
------------+-------------
 old        | comment old
(1 row)

# alter table old rename to new;
ALTER TABLE

# select c.relname table_name, pg_catalog.obj_description(c.oid) as comment 
from pg_catalog.pg_class c where c.relname = 'old';
 table_name | comment 
------------+---------
(0 rows)

# select c.relname table_name, pg_catalog.obj_description(c.oid) as comment 
from pg_catalog.pg_class c where c.relname = 'new';
 table_name |   comment   
------------+-------------
 new        | comment old
(1 row)

#