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
--
Ticket URL: <https://code.djangoproject.com/ticket/29719>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Old description:
> 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
New description:
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
https://github.com/django/django/pull/10351
--
--
Ticket URL: <https://code.djangoproject.com/ticket/29719#comment:1>
* stage: Unreviewed => Accepted
* type: Bug => New feature
* easy: 1 => 0
* needs_tests: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/29719#comment:2>
Old description:
> 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
>
> https://github.com/django/django/pull/10351
New description:
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
[https://github.com/django/django/pull/10351 PR]
--
--
Ticket URL: <https://code.djangoproject.com/ticket/29719#comment:3>
* owner: Luke => Nick Pope
* keywords: postgres,fdw,foreign data wrapper => postgresql,
introspection, inspectdb, fdw, foreign data wrapper
* version: 2.1 => master
* needs_tests: 1 => 0
Comment:
Updated [https://github.com/django/django/pull/10385 PR].
--
Ticket URL: <https://code.djangoproject.com/ticket/29719#comment:4>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"45ef3df7d07489ee0b76479cc799faa92e443a69" 45ef3df7]:
{{{
#!CommitTicketReference repository=""
revision="45ef3df7d07489ee0b76479cc799faa92e443a69"
Fixed #29719 -- Added introspection of foreign tables for PostgreSQL.
Thanks infinite-l00p for the initial patch.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29719#comment:5>