Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1v8KUB-00GQDI-3F for pgsql-bugs@arkaria.postgresql.org; Mon, 13 Oct 2025 15:29:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1v8KU8-006YBY-SF for pgsql-bugs@arkaria.postgresql.org; Mon, 13 Oct 2025 15:29:17 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1v8KU8-006YBQ-Jj for pgsql-bugs@lists.postgresql.org; Mon, 13 Oct 2025 15:29:17 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1v8KU7-001x4X-07 for pgsql-bugs@lists.postgresql.org; Mon, 13 Oct 2025 15:29:17 +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 59DFTCo5232358; Mon, 13 Oct 2025 11:29:12 -0400 From: Tom Lane To: turon.david@seznam.cz cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #19084: dump/restore table doesn't work with GENARETED column and custom type and cast in function In-reply-to: <19084-c3dd88cd54fff87a@postgresql.org> References: <19084-c3dd88cd54fff87a@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Mon, 13 Oct 2025 13:32:33 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <232356.1760369352.1@sss.pgh.pa.us> Date: Mon, 13 Oct 2025 11:29:12 -0400 Message-ID: <232357.1760369352@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk PG Bug reporting form writes: > CREATE FUNCTION f(data jsonb) RETURNS test_type[] AS $$ SELECT > array_agg((e->>'item')::test_type) FROM jsonb_array_elements(data->'test') > AS e $$ LANGUAGE SQL IMMUTABLE; The problem with this function is that it doesn't work unless type public.test_type is in the search_path. Which it is not during pg_restore (at least not with moderately-recent versions). You could either schema-qualify the reference to test_type, or switch the function to new-style SQL: CREATE FUNCTION f(data jsonb) RETURNS test_type[] IMMUTABLE BEGIN ATOMIC SELECT array_agg((e->>'item')::test_type) FROM jsonb_array_elements(data->'test') AS e; END; If you use that syntax then the test_type reference is parsed at function definition time instead of function execution, and everything is a lot safer. (The same goes for your other SQL-language function.) regards, tom lane