Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m1aKe-0006zA-JZ for pgsql-general@arkaria.postgresql.org; Thu, 08 Jul 2021 20:09:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m1aKd-0001Ag-7g for pgsql-general@arkaria.postgresql.org; Thu, 08 Jul 2021 20:09:11 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m1aKc-0001AY-Uy for pgsql-general@lists.postgresql.org; Thu, 08 Jul 2021 20:09:10 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m1aKa-0001ZO-61 for pgsql-general@lists.postgresql.org; Thu, 08 Jul 2021 20:09:09 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 168K92RX2040893; Thu, 8 Jul 2021 16:09:04 -0400 From: Tom Lane To: "Christopher Causer" cc: pgsql-general@lists.postgresql.org Subject: Re: =?UTF-8?Q?pg=5Fdump's_restore_gives_"operator_does_not_exist:_public.ipr?= =?UTF-8?Q?ange_=3D_public.iprange"_but_copy_paste_works?= In-reply-to: <8a602a2a-e0b8-42ef-8468-21fa2eb25bd9@www.fastmail.com> References: <8a602a2a-e0b8-42ef-8468-21fa2eb25bd9@www.fastmail.com> Comments: In-reply-to "Christopher Causer" message dated "Thu, 08 Jul 2021 20:50:36 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2040891.1625774942.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 08 Jul 2021 16:09:02 -0400 Message-ID: <2040892.1625774942@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "Christopher Causer" 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. Runnin= g `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 =3D 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.=3D). 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