@@ -39,12 +39,7 @@ class DatabaseObject(TypedDict):
3939SELECT c.oid AS table_id,
4040 c.relnamespace AS schema_id,
4141 c.relname AS table_name,
42- c.relhasindex AS has_indexes,
43- c.relowner :: regrole AS owner,
44- ( CASE
45- WHEN c.relkind = 'p' THEN TRUE
46- ELSE FALSE
47- END ) AS has_partitions,
42+ c.relowner :: regrole :: text AS table_owner,
4843 t.relname AS toast_table
4944FROM pg_class c
5045 left join pg_class t
@@ -57,8 +52,7 @@ class DatabaseObject(TypedDict):
5752SELECT c.oid AS table_id,
5853 c.relnamespace AS schema_id,
5954 c.relname AS table_name,
60- c.relhasindex AS has_indexes,
61- c.relowner :: regrole AS owner,
55+ c.relowner :: regrole :: text AS table_owner,
6256 t.relname AS toast_table
6357FROM pg_class c
6458 left join pg_class t
@@ -176,10 +170,8 @@ class PostgresDatabaseObject(DatabaseObject):
176170 datname AS NAME,
177171 pg_encoding_to_char(encoding) AS encoding,
178172 rolname AS owner,
179- description
173+ shobj_description(db.oid, 'pg_database') AS description
180174FROM pg_catalog.pg_database db
181- LEFT JOIN pg_catalog.pg_description dc
182- ON dc.objoid = db.oid
183175 JOIN pg_roles a
184176 ON datdba = a.oid
185177 WHERE datname NOT LIKE 'template%'
@@ -328,7 +320,7 @@ def get_rows_query(self):
328320 ),
329321 schema_tables AS (
330322 SELECT schemas.schema_id, schemas.schema_name, schemas.schema_owner,
331- tables.table_id, tables.table_name
323+ tables.table_id, tables.table_name, tables.table_owner, tables.toast_table
332324 FROM schemas
333325 LEFT JOIN tables ON schemas.schema_id = tables.schema_id
334326 ORDER BY schemas.schema_name, tables.table_name
@@ -346,7 +338,7 @@ def get_rows_query(self):
346338 { partitions_ctes }
347339
348340 SELECT schema_tables.schema_id, schema_tables.schema_name, schema_tables.schema_owner,
349- schema_tables.table_id, schema_tables.table_name,
341+ schema_tables.table_id, schema_tables.table_name, schema_tables.table_owner, schema_tables.toast_table,
350342 array_agg(row_to_json(columns.*)) FILTER (WHERE columns.name IS NOT NULL) as columns,
351343 array_agg(row_to_json(indexes.*)) FILTER (WHERE indexes.name IS NOT NULL) as indexes,
352344 array_agg(row_to_json(constraints.*)) FILTER (WHERE constraints.name IS NOT NULL)
@@ -358,7 +350,7 @@ def get_rows_query(self):
358350 LEFT JOIN constraints ON schema_tables.table_id = constraints.table_id
359351 { partition_joins }
360352 GROUP BY schema_tables.schema_id, schema_tables.schema_name, schema_tables.schema_owner,
361- schema_tables.table_id, schema_tables.table_name
353+ schema_tables.table_id, schema_tables.table_name, schema_tables.table_owner, schema_tables.toast_table
362354 ;
363355 """
364356
@@ -386,7 +378,7 @@ def _map_row(self, database: DatabaseInfo, cursor_row) -> DatabaseObject:
386378 for k , v in {
387379 "id" : str (cursor_row .get ("table_id" )),
388380 "name" : cursor_row .get ("table_name" ),
389- "owner" : cursor_row .get ("owner " ),
381+ "owner" : cursor_row .get ("table_owner " ),
390382 # The query can create duplicates of the joined tables
391383 "columns" : list ({v and v ['name' ]: v for v in cursor_row .get ("columns" ) or []}.values ())[
392384 : self ._config .max_columns
@@ -401,7 +393,9 @@ def _map_row(self, database: DatabaseInfo, cursor_row) -> DatabaseObject:
401393 }.items ()
402394 if v is not None
403395 }
404- ],
396+ ]
397+ if cursor_row .get ("table_name" )
398+ else [],
405399 }.items ()
406400 if v is not None
407401 }
0 commit comments