problem with Pl/Pgsql function
От | Matteo Centenaro |
---|---|
Тема | problem with Pl/Pgsql function |
Дата | |
Msg-id | F1470xxDEA2VqFnW0kK00013ece@hotmail.com обсуждение исходный текст |
Ответы |
Re: problem with Pl/Pgsql function
("Josh Berkus" <josh@agliodbs.com>)
|
Список | pgsql-sql |
Hi I have a problem with this function: Declare rec_struttura record;rec_camp record;prov int;estra_capo int;id_lista int;estra_non int;rand int8;count int;count_estra int;count_idint;rand_doub float8;row int8;occ boolean;note varchar;pre char(4) /*NOT NULL := '02'*/;tel char(13) /*NOT NULL:= '342522'*/;com int;citta char(35);nome varchar;num int4;data_oggi date;capo int;cap char(5);capo_bool boolean; Begin For rec_struttura in Select * From struttura_campione Loop /* estraggo i dati della provincia considerata */ prov := rec_struttura.cod_prov; estra_capo := rec_struttura.num_capo; estra_non := rec_struttura.num_non_capo; /* estrazione dei nominativi nel capoluogo */ capo := 1; count_estra := 0; /* modificato andrea*/ <<caso>> while (count_estra < estra_capo) Loop count_estra := count_estra + 1; /*modificato andrea*/ /*Select into rand PERFORM random ();*/ /* in ogni caso bisogna rimappre randda o al ROW_COUNT della select, immagino che così vada piu' veloce il tutto anche perche' rand arriva fino a 2^31-1 ;) */ rand_doub:= random() ; count := 0; /* Questa select quante volte viene ripetuta? tante volte quanti sono i soggetti da estrarre? */ For rec_camp in Select note,prefisso,telefono1,cod_com,cod_prov,citta,nome_cogno,capoluo,estrazione,num_estra,cap From nominativi inner join comuni on citta = nome_com Where ((cod_prov = prov) and (capoluo=capo)) Loop /* bisogna trovare un modo piu' figo per beccare il record altrimenti fa troppi giri dentro sticicli */ GET DIAGNOSTICS row = ROW_COUNT; rand := round (rand_doub * row); if (rand > row) then /*questo l'ho messo perche' altrimenti alla fine ne estrae meno di quelli che servono*/ exit caso; end if; count := count + 1; if count = rand then /* modificato andrea, prima la condizione"not occ" */ if not rec_camp.occupato then note := rec_camp.note; pre := rec_camp.prefisso; tel := rec_camp.telefono1; if preIS NULL or tel IS NULL then exit caso; end if; com := rec_camp.cod_com; citta := rec_camp.citta; cap := rec_camp.cap nome := rec_camp.nome_cogno; num := rec_camp.num_estra; capo := rec_camp.capoluo; exit; else count_estra := count_estra -1; exit caso; end if; end if; End Loop; /* end del for*/ /* estraggo i dati dal record prescelto */ /*note := rec_camp.note; pre := rec_camp.prefisso; tel := rec_camp.telefono1; com := rec_camp.cod_com; citta := rec_camp.citta; nome := rec_camp.nome_cogno;*/ /* faccio l'update di occupato */ /*num := rec_camp.num_estra;*/ num := num + 1; data_oggi := now(); update nominativi set occupato = TRUE, num_estra = num, estrazione = data_oggi Where ((prefisso = pre) and (telefono1 = tel)); /* faccio l'insert su tab_estrazioni */ id_lista := nextval('tab_estrazioni_id_seq'); insert into tab_estrazioni values (id_lista, pre, tel); Get Diagnostics count_id = RESULT_OID; /* prendo l'ultimo id utilizzata */ /*Select into id_lista id From tab_estrazioni Where oid = count_id;*/ /* inserisco il record nella tabella campione_out */ if capo = 1 then capo_bool := True; else capo_bool := False; end if; insert into campione_out values (note,pre,tel,cap,com,prov,citta,nome,capo_bool,NULL,NULL,id_lista); End Loop; /* end del while*/ End Loop; /*del primo FOR ? */ return count_id; End; The error riported is: Fail to add null value in not null attribute prefisso The line which the error refere is: id_lista := nextval('tab_estrazioni_id_seq'); insert into tab_estrazioni values (id_lista, pre, tel); Has Anybody any suggest? Thanks! _________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
В списке pgsql-sql по дате отправления: