Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 236
IvoAtanasov Avatar asked Jul 19 '26 03:07

IvoAtanasov


1 Answers

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';

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!