DECLARE
r RECORD;
BEGIN
FOR r IN
SELECT relname AS partition_name
FROM pg_class c
JOIN pg_inherits i ON c.oid = i.inhrelid
JOIN pg_class p ON p.oid = i.inhparent
WHERE p.relname = l_tab
LOOP
-- Construct DROP TABLE for the child table
l_sql := format('DROP TABLE %I', r.partition_name);
EXECUTE l_sql;
END LOOP;
END;