1

Suppose I have a PostgreSQL table called master.products and another called account.products. The second one inherits from the first.

Is is possible to create a query to get the parent name and schema of the table account.products?

Erwin Brandstetter
  • 539,169
  • 125
  • 977
  • 1,137
Marcio Mazzucato
  • 8,343
  • 6
  • 62
  • 76

1 Answers1

2

You get this information from the system catalog pg_inherits.

SELECT inhparent::regclass::text
FROM   pg_catalog.pg_inherits
WHERE  inhrelid = 'account.product'::regclass;

The name is automatically schema-qualified to make it unambiguous according to the current search_path .

SQL Fiddle.

Related:

About regclass:

Community
  • 1
  • 1
Erwin Brandstetter
  • 539,169
  • 125
  • 977
  • 1,137