[英]How to get all tables owned by one user but not by others, one by one
[英]Programmatically get all tables of a database owned by a user
我创建了以下查询:
select
is_tables.table_name
from information_schema.tables is_tables
join pg_tables
on is_tables.table_name=pg_tables.tablename
where
is_tables.table_catalog='<mydatabase>'
and is_tables.table_schema<>'information_schema'
and is_tables.table_schema<>'pg_catalog'
and pg_tables.tableowner='<myuser>';
我假设没有数据库供应商独立的查询方式。 这是实现我在PostgreSQL中想要的最简单/最短的SQL查询吗?
我觉得你很亲密。 对象所有者似乎没有出现在information_schema视图中,尽管我可能忽略了它。
select is_tables.table_schema,
is_tables.table_name
from information_schema.tables is_tables
inner join pg_tables
on is_tables.table_name = pg_tables.tablename
and is_tables.table_schema = pg_tables.schemaname
where is_tables.table_catalog = '<mydatabase>'
and is_tables.table_schema <> 'information_schema'
and is_tables.table_schema <> 'pg_catalog'
and pg_tables.tableowner = '<myuser>';
您需要同时加入表名和架构名。 表名在模式中是唯一的; 它们在数据库中不是唯一的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.