在PSQL中,有没有找到从另一个表继承的所有表的好方法?理想情况下,我可以从SQL查询中获取数据,但此时,我对任何可靠的方法都很满意。
答案 0 :(得分:33)
你是什么意思“从SQL查询”?这是否意味着来自SELECT
的{{1}}对您来说不够好?
pg_inherits
答案 1 :(得分:5)
如果您还需要架构名称:
SELECT cn.nspname AS schema_child, c.relname AS child, pn.nspname AS schema_parent, p.relname AS parent
FROM pg_inherits
JOIN pg_class AS c ON (inhrelid=c.oid)
JOIN pg_class as p ON (inhparent=p.oid)
JOIN pg_namespace pn ON pn.oid = p.relnamespace
JOIN pg_namespace cn ON cn.oid = c.relnamespace
WHERE p.relname = 'your table name' and pn.nspname = 'your schema name'
答案 2 :(得分:1)
如果你想从主分区中找到所有孩子,你可以简单地执行它:
SELECT relname
FROM pg_class,pg_inherits
WHERE pg_class.oid=pg_inherits.inhrelid
AND inhparent
IN (SELECT oid FROM pg_class WHERE relname='your_master_partition')
ORDER BY relname;