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
  • 605,456
  • 145
  • 1,078
  • 1,228
Marcio Mazzucato
  • 8,841
  • 9
  • 64
  • 79

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
  • 605,456
  • 145
  • 1,078
  • 1,228