pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: mwisnicki@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #18836: Cannot import foreign schema under different schema name when foreign table uses row types
Date: Fri, 07 Mar 2025 20:14:42 -0500
Message-ID: <1154376.1741396482@sss.pgh.pa.us> (raw)
In-Reply-To: <18836-070c3c12d36a1331@postgresql.org>
References: <18836-070c3c12d36a1331@postgresql.org>

PG Bug reporting form <noreply@postgresql.org> writes:
> Assume foreign public schema has tables that use row types from the same
> schema, e.g.

>   CREATE TABLE public.foo();
>   CREATE TABLE public.bar(foo public.foo);

> If I try to import such schema under different local schema:

>   CREATE SCHEMA server1_foreign;
>   IMPORT FOREIGN SCHEMA public FROM SERVER server1 INTO server1_foreign;

> Then such import will fail due to mismatched schema of rowtype:

>> [42704] ERROR: type "public.foo" does not exist
>> Where: importing foreign table "bar"

Yeah, IMPORT FOREIGN SCHEMA has no idea that the tables might have any
interdependencies, so it just imports them in a random order.  (Looks
like the order is actually by table name, so that this specific
example is sure to fail, but if you swapped the table names it'd
work.)

The postgres_fdw documentation does disclaim this case working [1]:

    If the remote tables to be imported have columns of user-defined
    data types, the local server must have compatible types of the
    same names.

That is, said types must *already* exist.

In principle postgresImportForeignSchema could be taught to look
at the remote server's pg_depend data and do a topological sort
to ensure the tables are created in a dependency-aware order.
It'd be a lot of work though, and I'm not sure how far one could
move the needle for a sane amount of effort.  (That is, is this
specific pattern the only sort of cross-table dependency?
I'm far from sure about that.)  At some level this amounts to
re-implementing pg_dump inside postgres_fdw, which is not a task
I care to buy into.  But hey, maybe somebody will take an
interest in making it work better.

			regards, tom lane

[1] https://www.postgresql.org/docs/devel/postgres-fdw.html#POSTGRES-FDW-OPTIONS-IMPORTING





view thread (3+ messages)  latest in thread

Message-ID: <1154376.1741396482@sss.pgh.pa.us>
Permalink:  ../1154376.1741396482@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1154376.1741396482@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, mwisnicki@gmail.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #18836: Cannot import foreign schema under different schema name when foreign table uses row types
  In-Reply-To: <1154376.1741396482@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox