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

From Tom Lane
Subject Re: BUG #19084: dump/restore table doesn't work with GENARETED column and custom type and cast in function
Date
Msg-id 232357.1760369352@sss.pgh.pa.us
Whole thread Raw
In response to BUG #19084: dump/restore table doesn't work with GENARETED column and custom type and cast in function  (PG Bug reporting form <noreply@postgresql.org>)
List pgsql-bugs
PG Bug reporting form <noreply@postgresql.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



pgsql-bugs by date:

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