I thought it is straightforward but I couldn't find a way to list all tables and their creators (or owners) in Redshift. Any help/insight is welcome.
Asked
Active
Viewed 6.2k times
2 Answers
51
It was pg_tables table and here is the SQL:
select tablename, tableowner From pg_tables

kee
- 10,969
- 24
- 107
- 168
23
You can list Redshift tables, views and their owners by running this script:
SELECT n.nspname AS schema_name
, pg_get_userbyid(c.relowner) AS table_owner
, c.relname AS table_name
, CASE WHEN c.relkind = 'v' THEN 'view' ELSE 'table' END
AS table_type
, d.description AS table_description
FROM pg_class As c
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
LEFT JOIN pg_tablespace t ON t.oid = c.reltablespace
LEFT JOIN pg_description As d
ON (d.objoid = c.oid AND d.objsubid = 0)
WHERE c.relkind IN('r', 'v')
ORDER BY n.nspname, c.relname ;

LiriB
- 814
- 8
- 12
-
Nope. Doesn't work. Doesn't even show any tables in the public schema. – Appleoddity Dec 16 '21 at 17:21
-
@Appleoddity : works for me. Maybe you do not have sufficient permissions – Mitch Wheat May 14 '22 at 03:03