Opened 6 years ago
Last modified 6 years ago
#29719 closed New feature
command inspectdb run against postgres' foreign data wrapper (fdw) fails to list the foreign tables — at Version 1
Reported by: | Luke | Owned by: | Luke |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | postgresql, introspection, inspectdb, fdw, foreign data wrapper |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
When running the "inspectdb" command against a postgres database with foreign data wrapper (fdw) tables, these foreign tables aren't listed.
The bug arises here
line#41 of db/backends/postgresql/introspection.py
SELECT c.relname, c.relkind FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE c.relkind IN ('r', 'v') AND n.nspname NOT IN ('pg_catalog', 'pg_toast') AND pg_catalog.pg_table_is_visible(c.oid)""")
pg_class.relkind stores foreign tables as "F" , so the condition "c.relkind in ('r','v')" is never met .
The query must be rewritten as
SELECT c.relname, c.relkind FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE c.relkind IN ('r', 'v', 't') AND n.nspname NOT IN ('pg_catalog', 'pg_toast') AND pg_catalog.pg_table_is_visible(c.oid)""")
and on line#50
return [TableInfo(row[0], {'r': 't', 'v': 'v', 'f': 't'}.get(row[1])) for row in cursor.fetchall() if row[0] not in self.ignored_tables]
in order to map the 'f' to a table
I patched the file and made this pull-request
Note:
See TracTickets
for help on using tickets.