[SQL] Retrieve the column values of a record without knowing the names
Hello, 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? Thanks in advance. 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$ LANGUAGE plpgsql VOLATILE; -- View this message in context: http://postgresql.1045698.n5.nabble.com/Retrieve-the-column-values-of-a-record-without-knowing-the-names-tp3387935p3387935.html Sent from the PostgreSQL - sql mailing list archive at Nabble.com. -- Sent via pgsql-sql mailing list ([email protected]) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql
[SQL] Retrieve the column values of a record without knowing the names
Hello, 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? Thanks in advance. 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$ LANGUAGE plpgsql VOLATILE; -- View this message in context: http://postgresql.1045698.n5.nabble.com/Retrieve-the-column-values-of-a-record-without-knowing-the-names-tp3387932p3387932.html Sent from the PostgreSQL - sql mailing list archive at Nabble.com. -- Sent via pgsql-sql mailing list ([email protected]) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql
[SQL] Re: Retrieve the column values of a record without knowing the names
Very interesting... But with information_schema.columns is easier... Thanks anyway... -- View this message in context: http://postgresql.1045698.n5.nabble.com/Retrieve-the-column-values-of-a-record-without-knowing-the-names-tp3387932p3390948.html Sent from the PostgreSQL - sql mailing list archive at Nabble.com. -- Sent via pgsql-sql mailing list ([email protected]) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql
[SQL] Re: Retrieve the column values of a record without knowing the names
Wow, how I didn't think about this solution? Thanks a lot! So easy... -- View this message in context: http://postgresql.1045698.n5.nabble.com/Retrieve-the-column-values-of-a-record-without-knowing-the-names-tp3387932p3390950.html Sent from the PostgreSQL - sql mailing list archive at Nabble.com. -- Sent via pgsql-sql mailing list ([email protected]) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql
[SQL] Re: Retrieve the column values of a record without knowing the names
Wow, I don't know if I exposed the problem in the right way, but I'm not achieving the solution with information_schema... Let me show the function: CREATE OR REPLACE FUNCTION fc_teste_tce2(codigo_aluno integer) RETURNS character varying AS $BODY$ DECLARE reg record; reg2 record; msg character varying; i integer; BEGIN msg := ''; i := 0; for reg in SELECT * FROM estagio.vw_aluno_tce where aluno::integer = codigo_aluno loop for reg2 in select column_name from information_schema.columns where table_catalog = 'seduc' and table_schema = 'estagio' and table_name = 'vw_aluno_tce' loop if reg.reg2.column_name = '' then --> how can I do this to check if there's no value for the field? i := 1; end if; end loop; end loop; if (i = 1) then return 'Problems...'; else return 'ok'; end if; END; $BODY$ LANGUAGE plpgsql VOLATILE COST 100; Thanks a lot! -- View this message in context: http://postgresql.1045698.n5.nabble.com/Retrieve-the-column-values-of-a-record-without-knowing-the-names-tp3387932p3390966.html Sent from the PostgreSQL - sql mailing list archive at Nabble.com. -- Sent via pgsql-sql mailing list ([email protected]) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql
[SQL] Re: Retrieve the column values of a record without knowing the names
Thanks Dmitry Grishin. The only problem is that my DBA didn't permit install this command... :( But, I quit this problem... Thanks by attention... -- View this message in context: http://postgresql.1045698.n5.nabble.com/Retrieve-the-column-values-of-a-record-without-knowing-the-names-tp3387932p3396051.html Sent from the PostgreSQL - sql mailing list archive at Nabble.com. -- Sent via pgsql-sql mailing list ([email protected]) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql
