GP - SQL to fetch table(s) owned by given user
SQL
SELECT n.nspname||'.'||c.relname FROM pg_catalog.pg_class As c INNER JOIN pg_catalog.pg_namespace AS n ON c.relnamespace = n.oid AND n.nspname = '<schemaname>' AND c.relkind IN ('r','v') AND c.relstorage != 'x' INNER JOIN pg_catalog.pg_roles AS r ON c.relowner = r.oid AND r.rolname = '<userid>' EXCEPT SELECT partitionschemaname||'.'||partitiontablename FROM pg_catalog.pg_partitions ORDER BY 1;
Here
SELECT n.nspname||'.'||c.relname FROM pg_catalog.pg_class As c INNER JOIN pg_catalog.pg_namespace AS n ON c.relnamespace = n.oid AND n.nspname = '<schemaname>' AND c.relkind IN ('r','v') AND c.relstorage != 'x' INNER JOIN pg_catalog.pg_roles AS r ON c.relowner = r.oid AND r.rolname = '<userid>' EXCEPT SELECT partitionschemaname||'.'||partitiontablename FROM pg_catalog.pg_partitions ORDER BY 1;
Here
<schemaname> and <userid> can be supplied accordingly to fetch details.
Comments
Post a Comment