Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ftNwG-0001B0-9A for pgsql-bugs@arkaria.postgresql.org; Sat, 25 Aug 2018 02:04:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ftNwB-0002Ng-8v for pgsql-bugs@arkaria.postgresql.org; Sat, 25 Aug 2018 02:04:27 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ftNwA-0002NZ-R4 for pgsql-bugs@lists.postgresql.org; Sat, 25 Aug 2018 02:04:26 +0000 Received: from momjian.us ([72.94.173.45]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ftNw3-0006uz-E9 for pgsql-bugs@lists.postgresql.org; Sat, 25 Aug 2018 02:04:25 +0000 Received: from bruce by momjian.us with local (Exim 4.84_2) (envelope-from ) id 1ftNw2-0004aS-LB; Fri, 24 Aug 2018 22:04:18 -0400 Date: Fri, 24 Aug 2018 22:04:18 -0400 From: Bruce Momjian To: zgrannan@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15345: pg_upgrade from 9.6.10 to 10.5 fails due to function call in index definition Message-ID: <20180825020418.GA7869@momjian.us> References: <153491451667.1375.476837125433068071@wrigleys.postgresql.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <153491451667.1375.476837125433068071@wrigleys.postgresql.org> User-Agent: Mutt/1.5.23 (2014-03-12) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Wed, Aug 22, 2018 at 05:08:36AM +0000, PG Bug reporting form wrote: > The following bug has been logged on the website: > > Bug reference: 15345 > Logged by: Zack Grannan > Email address: zgrannan@gmail.com > PostgreSQL version: 10.5 > Operating system: NixOS > Description: > > It appears that pg_upgrade fails when it encounters a table with an index > computed by a function that itself calls another function. The following is > a simple example: > > CREATE TABLE things(a int, b int); > > CREATE FUNCTION subtract(int, int) RETURNS int > LANGUAGE sql IMMUTABLE > AS $_$ > SELECT $1 - $2 > $_$; > > CREATE FUNCTION f(int, int) RETURNS int > LANGUAGE sql IMMUTABLE > AS $_$ > SELECT subtract($1, $2) > $_$; > > CREATE INDEX diff_things ON things(f(a,b)); This is caused by security changes made in PG 10.3 and other minor releases. Please see this thread for an outline of the issue: https://www.postgresql.org/message-id/flat/152106914669.1223.5104148605998271987%40wrigleys.postgresql.org The fix is to prefix the function call by 'public': CREATE TABLE things(a int, b int); CREATE FUNCTION subtract(int, int) RETURNS int LANGUAGE sql IMMUTABLE AS $_$ SELECT $1 - $2 $_$; CREATE FUNCTION f(int, int) RETURNS int LANGUAGE sql IMMUTABLE AS $_$ --> SELECT public.subtract($1, $2) $_$; CREATE INDEX diff_things ON things(f(a,b)); -- Bruce Momjian http://momjian.us EnterpriseDB http://enterprisedb.com + As you are, so once was I. As I am, so you will be. + + Ancient Roman grave inscription +