#[ ZACATEK SOUBORU ]#

#DEF <SCHEMA>    food600
#DEF <PRIMARYKEY> idriadok
#DEF <TABLENAME> nlimitrov_hladiny

#[ CREATE TABLE ZACATEK ]#
    idriadok serial,
    id_den integer NOT NULL DEFAULT 0,
    id_rov integer NOT NULL DEFAULT 0,
    c_hlad integer NOT NULL DEFAULT 0,
    hodnota numeric(20,10) NOT NULL DEFAULT 0,
    pocet numeric(5,0) NOT NULL DEFAULT 0,
    lbl smallint NOT NULL DEFAULT 0,
    CONSTRAINT <TABLENAME>_<PRIMARYKEY> PRIMARY KEY (<PRIMARYKEY>)
#[ CREATE TABLE KONEC ]#

#[ IF EXIST ZACATEK ]#
#[ PRIMARYKEY ]#


	IF EXISTS (SELECT table_name FROM information_schema.tables WHERE table_schema='food600' and table_name='nlimitrov_hladiny') THEN 
		IF EXISTS (SELECT table_name FROM information_schema.tables WHERE table_schema='food600' and table_name='nlimitrov') THEN 
			insert into food600.nlimitrov_hladiny (id_den, id_rov,  c_hlad, hodnota, pocet) select id_den, id_rov, 1 as c_hlad, limit1, pocet1 from food600.nlimitrov where limit1<>0 or pocet1<>0;
			insert into food600.nlimitrov_hladiny (id_den, id_rov,  c_hlad, hodnota, pocet) select id_den, id_rov, 2 as c_hlad, limit2, pocet2 from food600.nlimitrov where limit2<>0 or pocet2<>0;
			update food600.nlimitrov set limit1=0, pocet1=0 where limit1<>0 or pocet1<>0;
			update food600.nlimitrov set limit2=0, pocet2=0 where limit2<>0 or pocet2<>0;
	END IF;
	END IF;


END IF;

#[ KONEC SOUBORU ]#