Leonardo Chaves wrote: > > Aproveitando a deixa do Osvaldo . As vezes eu caio nesse problema do into > . > > Minha forma de resolver é > > for max IN > execute $1 > Loop > --loop vazio > End loop; > > Qual outro jeito de fazer isso ? > > Em 29/05/07, Osvaldo Rosario Kussama <[EMAIL PROTECTED]> > escreveu: >> >> Charles Viana escreveu: >> > So que esta retornando NULO. O execute executa a query so que não passa >> > o valor para a variavel nnn >> > >> > 2007/5/26, Luiz Rafael Culik Guimaraes <[EMAIL PROTECTED] >> > <mailto:[EMAIL PROTECTED]>>: >> > >> > Ola >> > >> > Eu sugiro alterar oara >> > >> > >> > CREATE OR REPLACE FUNCTION execd(text) RETURNS integer AS >> > $BODY$ >> > declara >> > nnn integer; >> > begin >> > /* $1 seria '(SELECT MAX(codgeral) FROM histviag.carga)' */ >> > execute $1; >> > return nnn >> > >> > end;$BODY$ >> > LANGUAGE 'plpgsql' VOLATILE; >> > >> > e passaria sua query como >> > select max(codgeral) into nnn FROM histviag.carga >> > >> >> >> De acordo com o manual: >> >> http://www.postgresql.org/docs/8.2/interactive/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN >> "SELECT INTO is not currently supported within EXECUTE." >> > > Consultei mais detalhadamente o manual e achei a solução: http://www.postgresql.org/docs/8.2/interactive/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN EXECUTE command-string [ INTO [STRICT] target ]; Reparem a sutileza: não é SELECT INTO ... é EXECUTE 'SELECT ...' INTO ... bdteste=# CREATE OR REPLACE FUNCTION foo1(text) RETURNS numeric AS $$ bdteste$# DECLARE bdteste$# val numeric; bdteste$# BEGIN bdteste$# EXECUTE $1 INTO val; bdteste$# RETURN val; bdteste$# END; bdteste$# $$ LANGUAGE plpgsql; CREATE FUNCTION bdteste=# bdteste=# bdteste=# SELECT foo1('SELECT max(valor) FROM tst_val_null;'); foo1 --------- 1000.00 (1 registro) []s Osvaldo -- View this message in context: http://www.nabble.com/Execute-retornar-valor-tf3820946.html#a10859867 Sent from the PostgreSQL - Brasil mailing list archive at Nabble.com.
_______________________________________________ pgbr-geral mailing list pgbr-geral@listas.postgresql.org.br https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral