使用注释在 postgres sql 中创建视图

Ivo*_*sov 2 sql postgresql sql-view

我用 sql 语句在 postgres sql 中创建一个视图

CREATE OR REPLACE VIEW  {ViewName} as 
Select
.....
Run Code Online (Sandbox Code Playgroud)

我问有什么方法可以为视图中的列创建注释。创建视图后,在向列中添加注释时会生成错误:

错误:“{ViewName}”不是表、复合类型或外部表。

a_h*_*ame 6

要定义对列(或视图)的评论,请使用comment on

create view some_view
as
select x as col1, y as col2, z as col3
from some_table;
Run Code Online (Sandbox Code Playgroud)

然后:

comment on view some_view is 'Some View';
comment on column some_view.col1 is 'Originally column X';
Run Code Online (Sandbox Code Playgroud)