Re: pg_restore remap schema

From: Fabrice Chapuis <fabrice636861(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Guillaume Lelarge <guillaume(at)lelarge(dot)info>, "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>, Marcos Pegoraro <marcos(at)f10(dot)com(dot)br>
Subject: Re: pg_restore remap schema
Date: 2022-11-17 15:49:31
Message-ID: CAA5-nLD0+WpbxB+5z7_mcp9sFjO4vUvSFZc18C9nb64i5Eshdw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Postgres allows us to rename a schema with the command *alter schema
schema_orig rename to schema_dest*. however the definition of functions
belonging to the original schema are not modified.
CREATE OR REPLACE FUNCTION foo.fcount() RETURNS integer AS $$
declare
v_count integer;
BEGIN
select count(*)
into v_count

> from foo.test;

return v_count;
-- raise notice 'The number is: %', v_count;
END;
$$ LANGUAGE plpgsql;

select fcount();
fcount
2
(1 row)

alter schema foo rename to bar;
select fcount();
ERROR: relation "foo.test" does not exist
LINE 2: from foo.test
^
Implementing the remap feature seemed to me feasible since this logic was
similar to that of the native rename function.
Oracle provides this option for its export tool.
But I will not go further in this way I don't want to go against the advice
of experts who have been working on the postgres code for years.

Thank you for your comments

Regards,

Fabrice

On Wed, Nov 16, 2022 at 3:42 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Guillaume Lelarge <guillaume(at)lelarge(dot)info> writes:
> > Le mer. 16 nov. 2022 à 13:08, Fabrice Chapuis <fabrice636861(at)gmail(dot)com>
> a
> > écrit :
> >> I worked on the pg_dump source code to add remap schema functionality to
> >> use it internally where I work. This is a first version that allows to
> >> remap tables, views and sequences (only to export schema). Is this
> >> development likely to interest the PG community and to continue this
> >> development further?
>
> > If it doesn't work on functions, that will be a big issue. And to be
> > honest, I don't think you can do it reliably on functions, especially
> with
> > dynamic queries in PL/pgsql.
>
> Yeah --- I fear there is no hope of making a feature like this that
> works reliably enough that we'd accept it. pg_restore is just not
> that smart about what is in the chunks of DDL that it processes,
> and trying to make it smart enough is a losing game.
>
> regards, tom lane
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2022-11-17 15:52:56 Re: Postgresql 11.3 doesn't use gist index on polygon column
Previous Message Вадим Самохин 2022-11-17 15:45:02 Postgresql 11.3 doesn't use gist index on polygon column