@@ -58,35 +58,25 @@ def __init__(self, connection_info: RedshiftConnectionInfo):
5858
5959 def get_table_list (self ) -> list [Table ]:
6060 sql = """
61- SELECT
62- t.table_catalog,
63- t.table_schema,
64- t.table_name,
65- c.column_name,
66- c.data_type,
67- c.is_nullable,
68- c.ordinal_position,
69- obj_description(cls.oid) AS table_comment,
70- col_description(cls.oid, a.attnum) AS column_comment
71- FROM
72- information_schema.tables t
73- JOIN
74- information_schema.columns c
75- ON t.table_schema = c.table_schema
76- AND t.table_name = c.table_name
77- LEFT JOIN
78- pg_class cls
79- ON cls.relname = t.table_name
80- AND cls.relnamespace = (
81- SELECT oid FROM pg_namespace WHERE nspname = t.table_schema
82- )
83- LEFT JOIN
84- pg_attribute a
85- ON a.attrelid = cls.oid
86- AND a.attname = c.column_name
87- WHERE
88- t.table_type IN ('BASE TABLE', 'VIEW')
89- AND t.table_schema NOT IN ('information_schema', 'pg_catalog');
61+ SELECT
62+ current_database() AS table_catalog,
63+ n.nspname AS table_schema,
64+ c.relname AS table_name,
65+ a.attname AS column_name,
66+ format_type(a.atttypid, a.atttypmod) AS data_type,
67+ CASE WHEN a.attnotnull THEN 'NO' ELSE 'YES' END AS is_nullable,
68+ a.attnum AS ordinal_position,
69+ obj_description(c.oid) AS table_comment,
70+ col_description(c.oid, a.attnum) AS column_comment
71+ FROM pg_class c
72+ JOIN pg_namespace n ON n.oid = c.relnamespace
73+ JOIN pg_attribute a ON a.attrelid = c.oid
74+ WHERE c.relkind IN ('r', 'v') -- r = table, v = view
75+ AND a.attnum > 0 -- exclude system columns
76+ AND NOT a.attisdropped -- exclude dropped columns
77+ AND n.nspname NOT IN ('information_schema', 'pg_catalog', 'pg_internal')
78+ AND has_schema_privilege(n.nspname, 'USAGE')
79+ ORDER BY n.nspname, c.relname, a.attnum;
9080 """
9181 response = self .connector .query (sql ).to_pylist ()
9282
0 commit comments