Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eyEHJ-0003Pk-HD for pgsql-bugs@arkaria.postgresql.org; Tue, 20 Mar 2018 10:14:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1eyEHI-0006sT-B5 for pgsql-bugs@arkaria.postgresql.org; Tue, 20 Mar 2018 10:14:00 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eyEHI-0006sJ-59 for pgsql-bugs@lists.postgresql.org; Tue, 20 Mar 2018 10:14:00 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eyEHF-0001p6-42 for pgsql-bugs@lists.postgresql.org; Tue, 20 Mar 2018 10:13:59 +0000 Received: from [192.168.127.1] (port=18675 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.88 (FreeBSD)) (envelope-from ) id 1eyEHC-0001Ke-KY; Tue, 20 Mar 2018 10:13:54 +0000 Received: from [127.0.0.1] (port=22869 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.89 (FreeBSD)) (envelope-from ) id 1eyEHB-0007Tj-Uh; Tue, 20 Mar 2018 10:13:54 +0000 From: Andrew Gierth To: pgsql-bugs@lists.postgresql.org, asier.lostale@openbravo.com Subject: Re: BUG #15122: can't import data if table has a constraint with a function calling another function In-Reply-To: <152153826367.11956.8092048336300020216@wrigleys.postgresql.org> (PG Bug reporting form's message of "Tue, 20 Mar 2018 09:31:03 +0000") Message-ID: <87r2off4fc.fsf@news-spur.riddles.org.uk> References: <152153826367.11956.8092048336300020216@wrigleys.postgresql.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (berkeley-unix) Date: Tue, 20 Mar 2018 10:13:53 +0000 MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >>>>> "PG" == PG Bug reporting form writes: PG> Using only public schema, data in tables that use in check PG> constraints functions that invoke other functions does not get PG> imported with pg_restore after it was dumped with pg_dump. But if PG> functions in check constraints do not invoke other functions, data PG> is correctly imported. PG> I have noted this behavior after minor upgrading from 9.3.22 to PG> 9.3.23 and from 9.4.16 to 9.4.17; in 9.3.22 and 9.3.17 it worked PG> fine. This is definitely fallout from the security fixes related to search_path. PG> But it's unclear to me why having one level public functions is PG> allowed but it is not those functions to invoke other ones. It PG> looks inconsistent. Yes, the reason for this is that function bodies are for the most part treated as opaque strings everywhere except when actually executing the function. This means that when a function makes a non-schema-qualified reference to another function in its body, the search_path lookup is performed at runtime, and so it depends on the runtime setting of search_path. In contrast, a CHECK constraint stores a pre-parsed expression tree which refers to the function by its oid, not name, so that when pg_dump dumps it out as SQL it can use a schema-qualified name in the output. Since pg_dump now does the restore with only pg_catalog in the search_path, the first function is successfully called because it is schema-qualified in the CHECK constraint definition, but the second function is not found because it is referenced only by an unqualified name. You could do this: PG> return is_even(n) and n > 0; return public.is_even(n) and n > 0; -- Andrew (irc:RhodiumToad)