I've got the following function and I want to access the fields values of my record by index. The problem is that my select is retrieving each record line with all values and not each one of each row on my view... How can I solve this problem?
You can easily iterate across records from PL/pgSQL by using hstore, e.g: SELECT (avals(hstore(ROW(83,6,4))))[3]; dmitigr=> SELECT (avals(hstore(ROW(83,6,4))))[3] AS thirdfield; thirdfield ------------ 4 (1 row)
CREATE FUNCTION fc_teste_tce(aluno integer) RETURNS character varying AS $BODY$ DECLARE reg record; BEGIN for reg in execute 'SELECT ARRAY (SELECT vw_teste_tce FROM estagio.vw_teste_tce where aluno = ''3043'' LIMIT 20) AS campos' loop for j in 1..array_upper(reg.campos,1) loop raise notice 'Field Value: %',reg.campos[j]; end loop; end loop; return 'ok'; END; $BODY$