4

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.

1

2 Answers 2

10

You could query it from information_schema.tables:

SELECT table_catalog, table_schema 
FROM   information_schema.tables 
WHERE  table_name = 'student'
Sign up to request clarification or add additional context in comments.

2 Comments

what table_catalog means? will it work on views as well?
@John table_catalog is the name of the database containing the table. If you already know it, you can omit it from the query. And yes, this will work for views as well.
2
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.