Search code examples
sqlpostgresqlselectdata-dictionary

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.


Solution

  • You could query it from information_schema.tables:

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