Thread: PL/pgsql question

PL/pgsql question

From
"Andrea Suisani"
Date:
hi,
i define a function using pgacces with pl/pgsql.
it seems that the queries define in the function wasn't executed.
if I try to excute the same queries from the psql everything, really, works
fine.
the body of the function is:

-----------------------------------
Declarerec_struttura record;estra_capo float8;estra_non float8;rand_doub float8;row float8;capo int;i int;rand_max
float8;

Begini:=0;For rec_struttura in Select * From struttura_campione Loop i:=i+1;
 prov := rec_struttura.cod_prov; estra_capo := rec_struttura.num_capo; estra_non := rec_struttura.num_non_capo;
 capo := 1; row:=prova_rand(prov,capo,1)::float8; rand_doub:=(estra_capo/row);
 if i = 1 then  create table tmp as select * from veneto where cod_prov=prov and
capoluo=capo and rand < rand_doub and occupato = false limit estra_capo; end if;
 if i > 1 then  insert into tmp select * from veneto where cod_prov=prov and capoluo=capo
and rand < rand_doub and occupato = false limit estra_capo ; end if;
 insert into campione_out select note, prefisso, telefono1 as telefono,
cap, cod_com, cod_prov, citta, nome_cogno as nome_cognome, capoluo,
estrazione as ultimo_acesso,  rand from tmp;
 insert into tab_estrazioni (prefisso,telefono) select  prefisso as
presisso, telefono1 as telefono from tmp;
 delete from tmp; rand_max:=prova_rand(prov,capo,2);
update veneto set  occupato = true, estrazione = now()     where (capoluo =
capo and cod_prov = prov) and (rand <= rand_max) and occupato=false ;
end loop;
return rand_doub;

end;

--------------------------------------------------------------

no errors are report in log file during the excution of this function.
What should i change in the function?
Thanks in advance for any advice

Andrea

P.S. i'm sorry for my bad english