Avoid multiple calls on same function when expanding composite result
问题 I have an SQL function retuning a composite result. CREATE TYPE result_t AS (a int, b int, c int, d numeric); CREATE OR REPLACE FUNCTION slow_function(int) RETURNS result_t AS $$ -- just some placeholder code to make it slow SELECT 0, 0, 0, ( SELECT sum(ln(i::numeric)) FROM generate_series(1, $1) i ) $$ LANGUAGE sql IMMUTABLE; When calling the function, I would like to have the parts of the composite type expanded into several columns. That works fine when I call: SELECT (slow_function(i)).*