John
John

Reputation: 1852

postgresql: for a given table name what is schema name?

I have a table name student and like 35 schemas in my DB. how can i get in which schema the table student exists? (there might be more than one in different schemas).

I've tried through pg_class but I don't know how to get schema name from there.

Upvotes: 4

Views: 12354

Answers (2)

Kondala vinod raja
Kondala vinod raja

Reputation: 51

select schemaname,relname from pg_stat_user_tables;

Example:

dvdrental=# select schemaname,relname from pg_stat_user_tables;
schemaname relname
public actor
public category
public payment
public film
public staff

Upvotes: 2

Mureinik
Mureinik

Reputation: 312259

You could query it from information_schema.tables:

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

Upvotes: 10

Related Questions