Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL, get all partitioned table names and all NOT partiotioned table names

How can I get the name of all the non partitioned tables in my DB ? I use PostgresSQL 9.6

And how do I get the names of the partitioned tables only ?

For now I have the names of the partions in my DB, specifying a table name, but I need to do that dinamically.

SELECT i.inhrelid::regclass AS child
FROM   pg_inherits i
WHERE  i.inhparent = 'public.documento'::regclass;
like image 950
Fjordo Avatar asked Sep 01 '25 20:09

Fjordo


1 Answers

pg_inherits records information about table and index inheritance hierarchies. If you need to get all partitioned tables only(exclude partitioned indexes), we can use:

select relnamespace::regnamespace::text schema_name, oid::regclass::text table_name from pg_class
where relkind = 'p' and oid in (select distinct inhparent from pg_inherits)
order by schema_name, table_name;
like image 79
Andrew Guppy Avatar answered Sep 03 '25 10:09

Andrew Guppy