Re: BUG #14700: pg_restore doesn't declare schema in 'create function' statements

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: psuderevsky(at)gmail(dot)com
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #14700: pg_restore doesn't declare schema in 'create function' statements
Date: 2017-06-09 17:56:43
Message-ID: 5617.1497031003@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

psuderevsky(at)gmail(dot)com writes:
> When restoring only particular schema from dump with "pg_restore -n" it does
> the following:
> 1. SET search_path = yourschema, pg_catalog
> 2. CREATE FUNCTION yourfunction()

Yes, that's intentional.

> As a result, if you had forgotten creating yourschema before restoring then
> no objects will be restored except your functions, they will be restored in
> pg_catalog schema.
> These statements must be performed with direct schema reference: CREATE
> FUNCTION yourschema.yourfunction().

We're not doing that because it breaks other useful use-cases; in
particular, editing a dump to move things into another schema becomes
a lot harder. Even if we wanted to change pg_dump that way, it wouldn't
make things any safer for existing dump files.

There was a long discussion of whether to change anything in this area
a few years ago:

https://www.postgresql.org/message-id/flat/8c4600a6f10e7dd823a157eff9985068.squirrel%40webmail.xs4all.nl

That trailed off without any real consensus about what to do. Personally
I still like the idea of refusing to allow creates if the first schema
listed in search_path doesn't exist, but I was having a hard time selling
that plan :-(

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Bruce Momjian 2017-06-09 21:16:28 Re: BUG #14698: Little typo in the documentation
Previous Message Arthur Nascimento 2017-06-09 16:54:10 Re: Re: [BUGS] BUG #14695: Documentation is not accurate