Postgres: To get list of all partitions of a table
SELECT
child.relname AS partition_name
FROM
pg_class base_tb
JOIN
pg_inherits i ON i.inhparent = base_tb.oid
JOIN
pg_class child ON i.inhrelid = child.oid
LEFT JOIN
pg_partitioned_table pt ON pt.partrelid = child.oid
WHERE
base_tb.relname = 'coupons';
------------------------------
SELECT
nmsp_child.nspname AS partition_schema,
child.relname AS partition_name,
pg_get_userbyid(child.relowner) AS owner_name,
pg_get_expr(child.relpartbound, child.oid) AS partition_bound
FROM pg_inherits
JOIN pg_class parent ON pg_inherits.inhparent = parent.oid
JOIN pg_class child ON pg_inherits.inhrelid = child.oid
JOIN pg_namespace nmsp_child ON nmsp_child.oid = child.relnamespace
WHERE parent.relname = 'coupons'
AND child.relkind = 'r'
and child.relname like '%BEW%'
ORDER BY child.relname;
Comments
Post a Comment