Re: BUG #19084: dump/restore table doesn't work with GENARETED column and custom type and cast in function

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: turon(dot)david(at)seznam(dot)cz
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #19084: dump/restore table doesn't work with GENARETED column and custom type and cast in function
Date: 2025-10-13 15:29:12
Message-ID: 232357.1760369352@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

PG Bug reporting form <noreply(at)postgresql(dot)org> 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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Masahiko Sawada 2025-10-13 20:18:34 Re: TRAP: failed Assert("outerPlan != NULL") in postgres_fdw.c
Previous Message David G. Johnston 2025-10-13 15:19:46 Re: BUG #19084: dump/restore table doesn't work with GENARETED column and custom type and cast in function