IvoAtanasov IvoAtanasov -3 years ago 47
SQL Question

Create view in postgres sql with comments

I create a view in postgres sql with sql statement

CREATE OR REPLACE VIEW {ViewName} as
Select
.....


I am asking is there any way to create comments for columns in the view.
After the view is created, it generates an error when a comment is added to a column :


ERROR: "{ViewName}" is not a table, composite type, or foreign table.

Answer Source

To define a comment on a column (or a view) use comment on:

create view some_view
as
select x as col1, y as col2, z as col3
from some_table;

Then:

comment on view some_view is 'Some View';
comment on column some_view.col1 is 'Originally column X';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download