【问题标题】:Is there any way to list all the views related to a table in the existing postgres schema有没有办法列出与现有 postgres 模式中的表相关的所有视图
【发布时间】:2021-11-26 05:26:25
【问题描述】:
我有一个包含多个模式的 Postgres 数据库。我正在尝试使用最佳数据类型优化我的数据库表。更多时候我以错误结束
不能改变视图使用的列的类型
在使用查询alter table schema.tbl_name alter column column_name type varchar(5) using column_name::varchar(5); 时
有什么方法(函数)可以列出与表格相关的所有视图吗?
【问题讨论】:
标签:
postgresql
function
view
alter-table
database-optimization
【解决方案1】:
使用这个查询:
select
u.view_schema schema_name,
u.view_name,
u.table_schema referenced_table_schema,
u.table_name referenced_table_name,
v.view_definition
from information_schema.view_table_usage u
join information_schema.views v on u.view_schema = v.table_schema
and u.view_name = v.table_name
where u.table_schema not in ('information_schema', 'pg_catalog')
order by u.view_schema, u.view_name
来源:Dataedo.com的文章List tables used by a view in PostgreSQL database