By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
Help with an interesting Postgres question: Why isn't an Index Only Scan used on a partition accessed via the parent table?.
create function foo(text)
returns jsonb
immutable parallel safe
return case $1
when 'a' then '{"k":"v"}'
else $1::jsonb
end;
CREATE FUNCTION
create function foo_wrapper(val text)
returns TABLE(results jsonb, _result boolean)
immutable parallel safe as $$
BEGIN RETURN QUERY
SELECT*,TRUE FROM foo(val);
EXCEPTION WHEN OTHERS THEN RETURN QUERY
SELECT '{}'::jsonb,FALSE;
END$$language plpgsql;
CREATE FUNCTION
select foo_wrapper('a');--ok
foo_wrapper |
---|
("{""k"": ""v""}",t) |
SELECT 1
select foo_wrapper('x');--ok,caught
foo_wrapper |
---|
({},f) |
SELECT 1
create table t as select generate_series(1,3e5)n;
SELECT 300000
--fails if it gets a parallel plan
explain analyze verbose
select foo_wrapper('x')
from t;
ERROR: cannot start subtransactions during a parallel operation CONTEXT: PL/pgSQL function foo_wrapper(text) line 2 during statement block entry