在 postgres sql 中创建带有评论的视图
Create view in postgres sql with comments
我在 postgres sql 中使用 sql 语句创建了一个视图
CREATE OR REPLACE VIEW {ViewName} as
Select
.....
我想问有没有什么方法可以为视图中的列创建注释。
创建视图后,在向列添加注释时会生成错误:
ERROR: "{ViewName}" is not a table, composite type, or foreign table.
要在列(或视图)上定义注释,请使用 comment on
:
create view some_view
as
select x as col1, y as col2, z as col3
from some_table;
然后:
comment on view some_view is 'Some View';
comment on column some_view.col1 is 'Originally column X';
使用虚拟 select 语句。
select 'general information for the use of the comments' as c1;
它很笨重,但这是我能找到的唯一嵌入评论的方法。
对于较大的项目,我在 header.
中创建评论
with query_header as (
select 'purpose - statement' as c1,
select 'revision - revised 16 Oct 2019 by WDH' as c2
select 'owner - contact details' as c3
select 'lines 234-312 to declutter orders with no valid partnmber' as c4
select 'join on itemtable changed to left join 23July2018 by WDH' as c5
)
我在 postgres sql 中使用 sql 语句创建了一个视图
CREATE OR REPLACE VIEW {ViewName} as
Select
.....
我想问有没有什么方法可以为视图中的列创建注释。 创建视图后,在向列添加注释时会生成错误:
ERROR: "{ViewName}" is not a table, composite type, or foreign table.
要在列(或视图)上定义注释,请使用 comment on
:
create view some_view
as
select x as col1, y as col2, z as col3
from some_table;
然后:
comment on view some_view is 'Some View';
comment on column some_view.col1 is 'Originally column X';
使用虚拟 select 语句。
select 'general information for the use of the comments' as c1;
它很笨重,但这是我能找到的唯一嵌入评论的方法。 对于较大的项目,我在 header.
中创建评论with query_header as (
select 'purpose - statement' as c1,
select 'revision - revised 16 Oct 2019 by WDH' as c2
select 'owner - contact details' as c3
select 'lines 234-312 to declutter orders with no valid partnmber' as c4
select 'join on itemtable changed to left join 23July2018 by WDH' as c5
)