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

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: BUG #19084: dump/restore table doesn't work with GENARETED column and custom type and cast in function
Дата
Msg-id 232357.1760369352@sss.pgh.pa.us
обсуждение исходный текст
Ответ на 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>)
Список 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 по дате отправления: