作者:靠谱的留一手_267 | 来源:互联网 | 2023-02-01 22:49
当我从复杂查询创建视图时,我需要保留我在SQL查询中添加的注释,以便更容易地返回到视图定义.在pgAdminIII中,当我创建一个视图然后查阅视图定义时,注释被删除并且缩进完全修改了......有没有办法改变这种行为?
查看创建:
CREATE OR REPLACE VIEW public.v_test AS
-- Count number of null lines within table 'test'
(SELECT * FROM public.test WHERE client IS NULL);
创建后查看定义,如pgAdminIII中所示:
-- View: v_test
-- DROP VIEW v_test;
CREATE OR REPLACE VIEW v_test AS
SELECT test.gid,
test.client
FROM test
WHERE test.client IS NULL;
ALTER TABLE v_test
OWNER TO postgres;
感谢帮助!
1> Joseph Lee..:
不,Postgres将视图保存为解析树,因此它不记得空格或注释.
但是,如果你真的需要它,functions
可以记住评论.
2> klin..:
Postgres不会按原样存储视图定义,因此您无法以这种方式存储注释.使用comment
命令:
create view my_view as select 1;
comment on view my_view is 'It is my view';
select obj_description('my_view'::regclass);
obj_description
-----------------
It is my view
(1 row)
你可以在PgAdmin3中看到评论:
-- View: public.my_view
-- DROP VIEW public.my_view;
CREATE OR REPLACE VIEW public.my_view AS
SELECT 1;
ALTER TABLE public.my_view
OWNER TO postgres;
COMMENT ON VIEW public.my_view
IS 'it is my view';