From: Tom Lane <tgl@sss.pgh.pa.us>
To: Christopher Causer <chy.causer@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: pg_dump's restore gives "operator does not exist: public.iprange = public.iprange" but copy paste works
Date: Thu, 08 Jul 2021 16:09:02 -0400
Message-ID: <2040892.1625774942@sss.pgh.pa.us> (raw)
In-Reply-To: <8a602a2a-e0b8-42ef-8468-21fa2eb25bd9@www.fastmail.com>
References: <8a602a2a-e0b8-42ef-8468-21fa2eb25bd9@www.fastmail.com>
"Christopher Causer" <chy.causer@gmail.com> writes:
> I have a large database whose schema I have recently changed. Since then I cannot restore its dump using the normal `psql -1 -f ...` route. Running `psql -1 -f ...` gives the error shown in the subject, yet pasting the failing view in the terminal afterwards is successful.
The core problem here is that this view definition:
CREATE VIEW archive.subnet_dhcp_options AS
...
JOIN public.subnets s USING (subnet_range));
is not safe against varying settings of the search_path. It needs the
"iprange = iprange" operator, which you've placed in the public schema;
so if that's not in the search_path when the view is defined, you lose.
Ordinarily pg_dump would account for this by writing out a
schema-qualified operator name, ie OPERATOR(public.=). But the
JOIN USING syntax involves no explicit operator name so there's
no way to do that.
This isn't the only SQL syntax that has implicit operators; CASE is
another example, and I think there are more. We've discussed inventing
non-SQL-spec syntax that can cope with explicitly writing a qualified
operator name in all these cases, but it looks like a messy project
with an ugly final result :-(, so nothing's been done yet.
I don't think there's any good solution right now. You could perhaps
put the iprange extension in pg_catalog not public, so that it's always
in the search path. I don't recall right now if that has any downsides.
regards, tom lane
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, chy.causer@gmail.com
Subject: Re: pg_dump's restore gives "operator does not exist: public.iprange = public.iprange" but copy paste works
In-Reply-To: <2040892.1625774942@sss.pgh.pa.us>
References: <8a602a2a-e0b8-42ef-8468-21fa2eb25bd9@www.fastmail.com> <2040892.1625774942@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