We can use the below to find out the parent object of the target object:
SELECT b.refobjid as oid,
b.refobjid::regclass as object,
a.refobjid as parent_oid,
a.refobjid::regclass as parent_object
FROM
pg_depend a,
pg_depend b
WHERE a.refclassid = 1259 -- this is pg_depend
AND a.classid = 2618 -- this is pg_rewrite
AND b.deptype = 'i' -- i means internal dependent
AND a.objid = b.objid
AND a.classid = b.classid
AND a.refclassid = b.refclassid
AND a.refobjid <> b.refobjid
AND b.refobjid=382890; -- set this value to the OID of the object you want to check
The result would be like:
oid | object | parent_oid | parent_object
--------+--------+------------+---------------
382890 | v4 | 382886 | v3
then try to search for v3's oid, and repeat this method until there is nothing returned.
oid | object | parent_oid | parent_object
--------+--------+------------+---------------
382886 | v3 | 382882 | v2
oid | object | parent_oid | parent_object
--------+--------+------------+---------------
382882 | v2 | 382878 | v1
oid | object | parent_oid | parent_object
--------+--------+------------+---------------
382878 | v1 | 382875 | test1