Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get schema of a table if I have the oid (Postgres 9.5.1)?

Tags:

postgresql

I'm trying to figure out how to get the schema of a table if I have the oid in Postgres 9.5.1. I tried using information_schema but can't figure out which table I use to join with the oid.

like image 473
Vincent Avatar asked May 03 '17 20:05

Vincent


1 Answers

You need to join pg_namespace to pg_class

select nsp.nspname as schema_name, tbl.relname as table_name
from pg_namespace nsp
  join pg_class tbl on nsp.oid = tbl.relnamespace
where tbl.oid = 42;
like image 144
a_horse_with_no_name Avatar answered Nov 15 '22 04:11

a_horse_with_no_name