Why this function return an empty table (while running the plain query from command line returns different values):
CREATE OR REPLACE FUNCTION get_area_values (_tbl regclass, _column text, indicator_id integer) RETURNS
TABLE (indicator integer, postcode text, date date, value double precision) AS $$
BEGIN
execute format(
'WITH ad AS (select distinct area, district from postcode_lookup)'
|| ' select $1 as indicator, ad.area as postcode, t.date, sum(t.%I) as value'
|| ' from %I as t'
|| ' join ad on t.postcode = ad.district group by ad.area, t.date', _column, _tbl)
USING indicator_id;
END
$$ LANGUAGE plpgsql;
I had even tried to use execute
with ||
without any luck.