pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Matteo Centenaro <gente_che_mixa@hotmail.com>
To: pgsql-sql@postgresql.org
Subject: problem with Pl/Pgsql function
Date: Tue, 05 Jun 2001 11:16:28 -0000
Message-ID: <F1470xxDEA2VqFnW0kK00013ece@hotmail.com> (raw)

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_id int;
	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 rand da 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 sti cicli */
				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 pre IS 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.




Message-ID: <F1470xxDEA2VqFnW0kK00013ece@hotmail.com>
Permalink:  ../F1470xxDEA2VqFnW0kK00013ece@hotmail.com/
Also on:    postgresql.org/message-id/F1470xxDEA2VqFnW0kK00013ece@hotmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: gente_che_mixa@hotmail.com
  Subject: Re: problem with Pl/Pgsql function
  In-Reply-To: <F1470xxDEA2VqFnW0kK00013ece@hotmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox