PostgreSQL:对于给定的表名,模式名称是什么?

4

我有一个名为student的表,在我的数据库中有大约35个模式。 如何知道表student存在于哪个模式中? (可能存在于不同的模式中)。

我尝试过通过pg_class来获取,但是我不知道如何从中获取模式名称。


http://www.postgresql.org/docs/9.4/static/catalog-pg-class.html 中的 relnamespace 字段指向包含模式的 pg_namespace.oid - wildplasser
2个回答

10

您可以从 information_schema.tables 查询它:

SELECT table_catalog, table_schema 
FROM   information_schema.tables 
WHERE  table_name = 'student'

什么是table_catalog?它在视图上也能用吗? - John
1
@John table_catalog 是包含表的数据库名称。如果您已经知道它,可以在查询中省略它。是的,这也适用于视图。 - Mureinik

2
select schemaname,relname from pg_stat_user_tables;

例子:

dvdrental=# select schemaname,relname from pg_stat_user_tables;
架构名称 关系名称
公共 演员
公共 类别
公共 支付
公共 电影
公共 员工
(注:原文为在PostgreSQL中查询各个表的名称)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接