----    slovenskaverzia=.T.       ----

CREATE OR REPLACE FUNCTION food600.synctabuliek(
	)
    RETURNS character varying
    LANGUAGE 'plpgsql'

    COST 100
    VOLATILE 
    
AS $BODY$
DECLARE 
ret	CHARACTER VARYING DEFAULT '' ;
pokracuj SMALLINT DEFAULT 1;
mojeid INTEGER;
mojmaster INTEGER;
mip CHARACTER VARYING;
mport CHARACTER VARYING;
mdatabaza CHARACTER VARYING;
mmeno CHARACTER VARYING;
mheslo CHARACTER VARYING;
mtabulka CHARACTER VARYING;
mdone INTEGER;
remverzia CHARACTER(10);
locverzia CHARACTER(10);
maxid BIGINT;
maxid2 BIGINT;
zoznamtabuliek CURSOR FOR SELECT tabulka FROM food600.sync_tables;
BEGIN
SELECT idriadok, id_master INTO mojeid, mojmaster FROM food600.sync_set WHERE tosomja>0 LIMIT 1;
RAISE NOTICE 'mojeid:%',mojeid;
RAISE NOTICE 'mojmaster:%',mojmaster;
IF mojeid IS NULL THEN
	--- V nastavovacej tabulke sa nenachadza moj zaznam, synchronizacia sa nerobi
	ret:='Nie je nastavený aktuálny server';
	mojeid:=0;
	mojmaster:=0;
END IF;       
IF mojeid>0 AND mojmaster>0 THEN
	SELECT ip, port, databaza, meno, heslo 
		INTO mip, mport, mdatabaza, mmeno, mheslo FROM food600.sync_set WHERE idriadok=mojmaster LIMIT 1;
	IF (mip IS NOT NULL) AND (mport IS NOT NULL) AND (mdatabaza IS NOT NULL) AND (mmeno IS NOT NULL) AND (mheslo IS NOT NULL) THEN
		RAISE NOTICE 'mdatabaza:%',mdatabaza;
		RAISE NOTICE 'mip:%',mip;
		RAISE NOTICE 'mport:%',mport;
		RAISE NOTICE 'mmeno:%',mmeno;
		RAISE NOTICE 'mheslo:%',mheslo;
		BEGIN
			PERFORM dblink_connect('connstrx','hostaddr='||btrim(mip)||' port='||btrim(mport)||' dbname='||btrim(mdatabaza)||' user='||btrim(mmeno)||' password='||btrim(mheslo));
		EXCEPTION
			WHEN duplicate_object THEN --code error 42710
				ret:='this connections exists';
			WHEN others	THEN
				ret:='nepripojene:%', sqlstate;
				pokracuj:=0;
		END;
		IF pokracuj>0 THEN
			SELECT data INTO remverzia FROM dblink('connstrx','SELECT data FROM food600.verzia LIMIT 1') as remzmeny(data CHARACTER(10)) ;
			SELECT data INTO locverzia FROM food600.verzia LIMIT 1;
			IF remverzia<>locverzia THEN
				mdone:=0;
				ret:='Nesúhlasia verzie databáz';
				raise notice 'nesuhlasia verzia databaz';
			ELSE
				mdone := 100000;
			END IF;
			OPEN zoznamtabuliek;
			raise notice 'otvoreny zoznam tabuliek';
			WHILE (mdone>0) LOOP
				FETCH zoznamtabuliek INTO mtabulka;
				IF mtabulka ISNULL THEN
					mdone:=0;
				ELSE
--	import tabulky
					raise notice 'tabulka:%',mtabulka;
					CASE
						WHEN btrim(mtabulka)='karty' THEN
							ALTER TABLE food600.karty DISABLE TRIGGER ALL;
							TRUNCATE food600.karty RESTART IDENTITY;
							INSERT INTO food600.karty(c_data, c_karty, nazev, c_druh, c_druhs, c_druhk, c_obalu, cena_prum, cena_nakup, obal_obsah,
								cena01, cena02, cena03, cena04, cena05, cena06, cena07, cena08, cena09, cena10, cena11, cena12,
								cena13, cena14, cena15, cena16, cena17, cena18, cena19, cena20, cena21, cena22, cena23, cena24,
								cena25, cena26, cena27, cena28, cena29, cena30, cena31, cena32, cena33, cena34, cena35, cena36,
								cena37, cena38, cena39, cena40, pocet, bar_kod1, bar_kod2, kod, dan1, dph, nazev1, nazev2, nazev3,
								nazev4, nazev5, naz1, naz2, naz3, naz4, naz5, vaha_obalu, vaha_koef, tolerance, vaha, lieh, objem,
								pov_objem, c_mena, c_mena_n, idriadok, stav, c_k_m)
								SELECT c_data, c_karty, nazev, c_druh, c_druhs, c_druhk, c_obalu, cena_prum, cena_nakup, obal_obsah,
								cena01, cena02, cena03, cena04, cena05, cena06, cena07, cena08, cena09, cena10, cena11, cena12,
								cena13, cena14, cena15, cena16, cena17, cena18, cena19, cena20, cena21, cena22, cena23, cena24,
								cena25, cena26, cena27, cena28, cena29, cena30, cena31, cena32, cena33, cena34, cena35, cena36,
								cena37, cena38, cena39, cena40, pocet, bar_kod1, bar_kod2, kod, dan1, dph, nazev1, nazev2, nazev3,
								nazev4, nazev5, naz1, naz2, naz3, naz4, naz5, vaha_obalu, vaha_koef, tolerance, vaha, lieh, objem,
								pov_objem, c_mena, c_mena_n, idriadok, stav, c_karty as c_k_m FROM dblink('connstrx','SELECT c_data, c_karty, nazev, c_druh, c_druhs, c_druhk, c_obalu, cena_prum, cena_nakup, obal_obsah,
								cena01, cena02, cena03, cena04, cena05, cena06, cena07, cena08, cena09, cena10, cena11, cena12,
								cena13, cena14, cena15, cena16, cena17, cena18, cena19, cena20, cena21, cena22, cena23, cena24,
								cena25, cena26, cena27, cena28, cena29, cena30, cena31, cena32, cena33, cena34, cena35, cena36,
								cena37, cena38, cena39, cena40, pocet, bar_kod1, bar_kod2, kod, dan1, dph, nazev1, nazev2, nazev3,
								nazev4, nazev5, naz1, naz2, naz3, naz4, naz5, vaha_obalu, vaha_koef, tolerance, vaha, lieh, objem,
								pov_objem, c_mena, c_mena_n, idriadok, stav FROM food600.karty ORDER BY idriadok') 
								as remzmeny(c_data INTEGER, c_karty INTEGER, nazev CHARACTER(30), c_druh INTEGER, c_druhs INTEGER, c_druhk INTEGER, c_obalu SMALLINT, cena_prum NUMERIC, cena_nakup NUMERIC, obal_obsah NUMERIC,
								cena01 NUMERIC, cena02 NUMERIC, cena03 NUMERIC, cena04 NUMERIC, cena05 NUMERIC, cena06 NUMERIC, cena07 NUMERIC, cena08 NUMERIC, cena09 NUMERIC, cena10 NUMERIC, cena11 NUMERIC, cena12 NUMERIC,
								cena13 NUMERIC, cena14 NUMERIC, cena15 NUMERIC, cena16 NUMERIC, cena17 NUMERIC, cena18 NUMERIC, cena19 NUMERIC, cena20 NUMERIC, cena21 NUMERIC, cena22 NUMERIC, cena23 NUMERIC, cena24 NUMERIC,
								cena25 NUMERIC, cena26 NUMERIC, cena27 NUMERIC, cena28 NUMERIC, cena29 NUMERIC, cena30 NUMERIC, cena31 NUMERIC, cena32 NUMERIC, cena33 NUMERIC, cena34 NUMERIC, cena35 NUMERIC, cena36 NUMERIC,
								cena37 NUMERIC, cena38 NUMERIC, cena39 NUMERIC, cena40 NUMERIC, pocet NUMERIC, bar_kod1 CHARACTER(26), bar_kod2 CHARACTER(13), kod CHARACTER(13), dan1 CHARACTER(1), dph NUMERIC, nazev1 CHARACTER(27), nazev2 CHARACTER(27), nazev3 CHARACTER(27),
								nazev4 CHARACTER(27), nazev5 CHARACTER(27), naz1 CHARACTER(30), naz2 CHARACTER(30), naz3 CHARACTER(30), naz4 CHARACTER(30), naz5 CHARACTER(30), vaha_obalu NUMERIC, vaha_koef NUMERIC, tolerance NUMERIC, vaha CHARACTER(10), lieh NUMERIC, objem NUMERIC,
								pov_objem NUMERIC, c_mena SMALLINT, c_mena_n SMALLINT, idriadok INTEGER, stav CHARACTER(1)) ;
							ALTER TABLE food600.karty ENABLE TRIGGER ALL;
							SELECT MAX(c_karty) INTO maxid FROM food600.karty;
							IF maxid IS NULL THEN
								maxid:=0;
							END IF;
							UPDATE food600.maxima SET i_max=maxid+1 WHERE btrim(soubor)='c_karty';
							IF NOT FOUND THEN
								INSERT INTO food600.maxima (soubor, i_max) VALUES ('c_karty',maxid+1);
							END IF;
							SELECT MAX(idriadok) into maxid FROM food600.karty;
							SELECT nextval('food600.karty_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.karty_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.karty_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='skupiny' THEN
							ALTER TABLE food600.skupiny DISABLE TRIGGER ALL;
							TRUNCATE food600.skupiny RESTART IDENTITY;
							INSERT INTO food600.skupiny(c_d_m, c_data, druh, spart, spart_kas, typ_skup, typ_skl, typ_kalk, prir2, dan01, dan02, dan03, dan04, dan05, dan06, dan07, dan08, dan09, dan10, dan11, dan12, dan13, dan14, dan15, dan16, dan17, dan18, dan19, dan20, dan21, dan22, dan23, dan24, dan25, dan26, dan27, dan28, dan29, dan30, dan31, dan32, dan33, dan34, dan35, dan36, dan37, dan38, dan39, dan40, druh1, druh2, druh3, druh4, druh5, poradie, c_druh, dotacia, sumar, zmena, samozdan, dan_samo, c_druh_2, c_druh_1, dana0, dana1, dana2, dana3, dana4, dana5, dana6, dana7, dana8, dana9, danb0, danb1, danb2, danb3, danb4, danb5, danb6, danb7, danb8, danb9, danc0, danc1, danc2, danc3, danc4, danc5, danc6, danc7, danc8, danc9, dand0, dand1, dand2, dand3, dand4, dand5, dand6, dand7, dand8, dand9, dane0, dane1, dane2, dane3, dane4, dane5, dane6, dane7, dane8, dane9, danf0, danf1, danf2, danf3, danf4, danf5, danf6, danf7, danf8, danf9, dang0, dang1, dang2, dang3, dang4, dang5, dang6, dang7, dang8, dang9, danh0, danh1, danh2, danh3, danh4, danh5, danh6, danh7, danh8, danh9, dani0, dani1, dani2, dani3, dani4, dani5, dani6, dani7, dani8, dani9, danj0, danj1, danj2, danj3, danj4, danj5, danj6, danj7, danj8, danj9, dank0, dank1, dank2, dank3, dank4, dank5, dank6, dank7, dank8, dank9, danl0, danl1, danl2, danl3, danl4, danl5, danl6, danl7, danl8, danl9)
								       SELECT c_druh as c_d_m, c_data, druh, spart, spart_kas, typ_skup, typ_skl, typ_kalk, prir2, dan01, dan02, dan03, dan04, dan05, dan06, dan07, dan08, dan09, dan10, dan11, dan12, dan13, dan14, dan15, dan16, dan17, dan18, dan19, dan20, dan21, dan22, dan23, dan24, dan25, dan26, dan27, dan28, dan29, dan30, dan31, dan32, dan33, dan34, dan35, dan36, dan37, dan38, dan39, dan40, druh1, druh2, druh3, druh4, druh5, poradie, c_druh, dotacia, sumar, zmena, samozdan, dan_samo, c_druh_2, c_druh_1, dana0, dana1, dana2, dana3, dana4, dana5, dana6, dana7, dana8, dana9, danb0, danb1, danb2, danb3, danb4, danb5, danb6, danb7, danb8, danb9, danc0, danc1, danc2, danc3, danc4, danc5, danc6, danc7, danc8, danc9, dand0, dand1, dand2, dand3, dand4, dand5, dand6, dand7, dand8, dand9, dane0, dane1, dane2, dane3, dane4, dane5, dane6, dane7, dane8, dane9, danf0, danf1, danf2, danf3, danf4, danf5, danf6, danf7, danf8, danf9, dang0, dang1, dang2, dang3, dang4, dang5, dang6, dang7, dang8, dang9, danh0, danh1, danh2, danh3, danh4, danh5, danh6, danh7, danh8, danh9, dani0, dani1, dani2, dani3, dani4, dani5, dani6, dani7, dani8, dani9, danj0, danj1, danj2, danj3, danj4, danj5, danj6, danj7, danj8, danj9, dank0, dank1, dank2, dank3, dank4, dank5, dank6, dank7, dank8, dank9, danl0, danl1, danl2, danl3, danl4, danl5, danl6, danl7, danl8, danl9 
  									    FROM dblink('connstrx','SELECT c_data, druh, spart, spart_kas, typ_skup, typ_skl, typ_kalk, prir2, dan01, dan02, dan03, dan04, dan05, dan06, dan07, dan08, dan09, dan10, dan11, dan12, dan13, dan14, dan15, dan16, dan17, dan18, dan19, dan20, dan21, dan22, dan23, dan24, dan25, dan26, dan27, dan28, dan29, dan30, dan31, dan32, dan33, dan34, dan35, dan36, dan37, dan38, dan39, dan40, druh1, druh2, druh3, druh4, druh5, poradie, c_druh, dotacia, sumar, zmena, samozdan, dan_samo, c_druh_2, c_druh_1, dana0, dana1, dana2, dana3, dana4, dana5, dana6, dana7, dana8, dana9, danb0, danb1, danb2, danb3, danb4, danb5, danb6, danb7, danb8, danb9, danc0, danc1, danc2, danc3, danc4, danc5, danc6, danc7, danc8, danc9, dand0, dand1, dand2, dand3, dand4, dand5, dand6, dand7, dand8, dand9, dane0, dane1, dane2, dane3, dane4, dane5, dane6, dane7, dane8, dane9, danf0, danf1, danf2, danf3, danf4, danf5, danf6, danf7, danf8, danf9, dang0, dang1, dang2, dang3, dang4, dang5, dang6, dang7, dang8, dang9, danh0, danh1, danh2, danh3, danh4, danh5, danh6, danh7, danh8, danh9, dani0, dani1, dani2, dani3, dani4, dani5, dani6, dani7, dani8, dani9, danj0, danj1, danj2, danj3, danj4, danj5, danj6, danj7, danj8, danj9, dank0, dank1, dank2, dank3, dank4, dank5, dank6, dank7, dank8, dank9, danl0, danl1, danl2, danl3, danl4, danl5, danl6, danl7, danl8, danl9 FROM food600.skupiny ORDER BY c_druh') 
								as remzmeny(c_data INTEGER, druh CHARACTER(10), spart CHARACTER(3), spart_kas CHARACTER(3), typ_skup CHARACTER(1), typ_skl CHARACTER(1), typ_kalk CHARACTER(1), prir2 NUMERIC(5,3), dan01 NUMERIC(5,3), dan02 NUMERIC(5,3), dan03 NUMERIC(5,3), dan04 NUMERIC(5,3), dan05 NUMERIC(5,3), dan06 NUMERIC(5,3), dan07 NUMERIC(5,3), dan08 NUMERIC(5,3), dan09 NUMERIC(5,3), dan10 NUMERIC(5,3), dan11 NUMERIC(5,3), dan12 NUMERIC(5,3), dan13 NUMERIC(5,3), dan14 NUMERIC(5,3), dan15 NUMERIC(5,3), dan16 NUMERIC(5,3), dan17 NUMERIC(5,3), dan18 NUMERIC(5,3), dan19 NUMERIC(5,3), dan20 NUMERIC(5,3), dan21 NUMERIC(5,3), dan22 NUMERIC(5,3), dan23 NUMERIC(5,3), dan24 NUMERIC(5,3), dan25 NUMERIC(5,3), dan26 NUMERIC(5,3), dan27 NUMERIC(5,3), dan28 NUMERIC(5,3), dan29 NUMERIC(5,3), dan30 NUMERIC(5,3), dan31 NUMERIC(5,3), dan32 NUMERIC(5,3), dan33 NUMERIC(5,3), dan34 NUMERIC(5,3), dan35 NUMERIC(5,3), dan36 NUMERIC(5,3), dan37 NUMERIC(5,3), dan38 NUMERIC(5,3), dan39 NUMERIC(5,3), dan40 NUMERIC(5,3), druh1 CHARACTER(30), druh2 CHARACTER(30), druh3 CHARACTER(30), druh4 CHARACTER(30), druh5 CHARACTER(30), poradie INTEGER, c_druh INTEGER, dotacia SMALLINT, sumar SMALLINT, zmena TIMESTAMP WITHOUT TIME ZONE, samozdan SMALLINT, dan_samo NUMERIC(5,3), c_druh_2 SMALLINT, c_druh_1 SMALLINT, dana0 NUMERIC(5,3), dana1 NUMERIC(5,3), dana2 NUMERIC(5,3), dana3 NUMERIC(5,3), dana4 NUMERIC(5,3), dana5 NUMERIC(5,3), dana6 NUMERIC(5,3), dana7 NUMERIC(5,3), dana8 NUMERIC(5,3), dana9 NUMERIC(5,3), danb0 NUMERIC(5,3), danb1 NUMERIC(5,3), danb2 NUMERIC(5,3), danb3 NUMERIC(5,3), danb4 NUMERIC(5,3), danb5 NUMERIC(5,3), danb6 NUMERIC(5,3), danb7 NUMERIC(5,3), danb8 NUMERIC(5,3), danb9 NUMERIC(5,3), danc0 NUMERIC(5,3), danc1 NUMERIC(5,3), danc2 NUMERIC(5,3), danc3 NUMERIC(5,3), danc4 NUMERIC(5,3), danc5 NUMERIC(5,3), danc6 NUMERIC(5,3), danc7 NUMERIC(5,3), danc8 NUMERIC(5,3), danc9 NUMERIC(5,3), dand0 NUMERIC(5,3), dand1 NUMERIC(5,3), dand2 NUMERIC(5,3), dand3 NUMERIC(5,3), dand4 NUMERIC(5,3), dand5 NUMERIC(5,3), dand6 NUMERIC(5,3), dand7 NUMERIC(5,3), dand8 NUMERIC(5,3), dand9 NUMERIC(5,3), dane0 NUMERIC(5,3), dane1 NUMERIC(5,3), dane2 NUMERIC(5,3), dane3 NUMERIC(5,3), dane4 NUMERIC(5,3), dane5 NUMERIC(5,3), dane6 NUMERIC(5,3), dane7 NUMERIC(5,3), dane8 NUMERIC(5,3), dane9 NUMERIC(5,3), danf0 NUMERIC(5,3), danf1 NUMERIC(5,3), danf2 NUMERIC(5,3), danf3 NUMERIC(5,3), danf4 NUMERIC(5,3), danf5 NUMERIC(5,3), danf6 NUMERIC(5,3), danf7 NUMERIC(5,3), danf8 NUMERIC(5,3), danf9 NUMERIC(5,3), dang0 NUMERIC(5,3), dang1 NUMERIC(5,3), dang2 NUMERIC(5,3), dang3 NUMERIC(5,3), dang4 NUMERIC(5,3), dang5 NUMERIC(5,3), dang6 NUMERIC(5,3), dang7 NUMERIC(5,3), dang8 NUMERIC(5,3), dang9 NUMERIC(5,3), danh0 NUMERIC(5,3), danh1 NUMERIC(5,3), danh2 NUMERIC(5,3), danh3 NUMERIC(5,3), danh4 NUMERIC(5,3), danh5 NUMERIC(5,3), danh6 NUMERIC(5,3), danh7 NUMERIC(5,3), danh8 NUMERIC(5,3), danh9 NUMERIC(5,3), dani0 NUMERIC(5,3), dani1 NUMERIC(5,3), dani2 NUMERIC(5,3), dani3 NUMERIC(5,3), dani4 NUMERIC(5,3), dani5 NUMERIC(5,3), dani6 NUMERIC(5,3), dani7 NUMERIC(5,3), dani8 NUMERIC(5,3), dani9 NUMERIC(5,3), danj0 NUMERIC(5,3), danj1 NUMERIC(5,3), danj2 NUMERIC(5,3), danj3 NUMERIC(5,3), danj4 NUMERIC(5,3), danj5 NUMERIC(5,3), danj6 NUMERIC(5,3), danj7 NUMERIC(5,3), danj8 NUMERIC(5,3), danj9 NUMERIC(5,3), dank0 NUMERIC(5,3), dank1 NUMERIC(5,3), dank2 NUMERIC(5,3), dank3 NUMERIC(5,3), dank4 NUMERIC(5,3), dank5 NUMERIC(5,3), dank6 NUMERIC(5,3), dank7 NUMERIC(5,3), dank8 NUMERIC(5,3), dank9 NUMERIC(5,3), danl0 NUMERIC(5,3), danl1 NUMERIC(5,3), danl2 NUMERIC(5,3), danl3 NUMERIC(5,3), danl4 NUMERIC(5,3), danl5 NUMERIC(5,3), danl6 NUMERIC(5,3), danl7 NUMERIC(5,3), danl8 NUMERIC(5,3), danl9 NUMERIC(5,3));
							ALTER TABLE food600.skupiny ENABLE TRIGGER ALL;
							SELECT MAX(c_druh) INTO maxid FROM food600.skupiny;
							IF maxid IS NULL THEN
								maxid:=0;
							END IF;
							UPDATE food600.maxima SET i_max=maxid+1 WHERE btrim(soubor)='c_druh';
							IF NOT FOUND THEN
								INSERT INTO food600.maxima (soubor, i_max) VALUES ('c_druh',maxid+1);
							END IF;
							SELECT nextval('food600.skupiny_c_druh_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.skupiny_c_druh_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.skupiny_c_druh_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='polozky' THEN
							ALTER TABLE food600.polozky DISABLE TRIGGER ALL;
							TRUNCATE food600.polozky RESTART IDENTITY;
							INSERT INTO food600.polozky(c_karty, c_poloz, hruba, cista, c_pozn, procento, id_man, poznamka, c_data, idriadok, poradie, idriadok_master)
								SELECT c_karty, c_poloz, hruba, cista, c_pozn, procento, id_man, poznamka, c_data, idriadok, poradie, idriadok as idriadok_master FROM dblink('connstrx','SELECT c_karty, c_poloz, hruba, cista, c_pozn, procento, id_man, poznamka, c_data, idriadok, poradie FROM food600.polozky ORDER BY idriadok') 
								as remzmeny(c_karty BIGINT, c_poloz BIGINT, hruba numeric(20,10), cista numeric(20,10), c_pozn SMALLINT, procento numeric(20,10), id_man CHARACTER(2), poznamka CHARACTER(10), c_data INTEGER, idriadok INTEGER, poradie INTEGER) ;
							ALTER TABLE food600.polozky ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.polozky;
							SELECT nextval('food600.polozky_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.polozky_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.polozky_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='umisteni' THEN
							ALTER TABLE food600.umisteni DISABLE TRIGGER ALL;
							TRUNCATE food600.umisteni RESTART IDENTITY;
							INSERT INTO food600.umisteni(c_karty, nazev, id_kas, id_man, prn_no, kod, rkod, c_druhk, c_data, idriadok, oblasta, oblastb, oblastc, zmena, idriadok_master)
								SELECT c_karty, nazev, id_kas, id_man, prn_no, kod, rkod, c_druhk, c_data, idriadok, oblasta, oblastb, oblastc, zmena, idriadok as idriadok_master FROM dblink('connstrx','SELECT c_karty, nazev, id_kas, id_man, prn_no, kod, rkod, c_druhk, c_data, idriadok, oblasta, oblastb, oblastc, zmena FROM food600.umisteni ORDER BY idriadok') 
								as remzmeny(c_karty BIGINT, nazev CHARACTER(30), id_kas CHARACTER(2), id_man CHARACTER(2), prn_no CHARACTER(2), kod CHARACTER(13), rkod CHARACTER(13), c_druhk BIGINT, c_data INTEGER, idriadok INTEGER, oblasta SMALLINT, oblastb SMALLINT, oblastc SMALLINT, zmena TIMESTAMP WITHOUT TIME ZONE) ;
							ALTER TABLE food600.umisteni ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.umisteni;
							SELECT nextval('food600.umisteni_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.umisteni_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.umisteni_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='umdruhy' THEN
							ALTER TABLE food600.umdruhy DISABLE TRIGGER ALL;
							TRUNCATE food600.umdruhy RESTART IDENTITY;
							INSERT INTO food600.umdruhy(c_druhk, id_kas, id_man, prn_no, c_data, idriadok, zmena, idriadok_master)
								SELECT c_druhk, id_kas, id_man, prn_no, c_data, idriadok, zmena, idriadok as idriadok_master FROM dblink('connstrx','SELECT c_druhk, id_kas, id_man, prn_no, c_data, idriadok, zmena FROM food600.umdruhy ORDER BY idriadok') 
								as remzmeny(c_druhk BIGINT, id_kas CHARACTER(2), id_man CHARACTER(2), prn_no CHARACTER(2), c_data INTEGER, idriadok INTEGER, zmena TIMESTAMP WITHOUT TIME ZONE) ;
							ALTER TABLE food600.umdruhy ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.karty;
							SELECT nextval('food600.umdruhy_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.umdruhy_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.umdruhy_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='eany' THEN
							ALTER TABLE food600.eany DISABLE TRIGGER ALL;
							TRUNCATE food600.eany RESTART IDENTITY;
							INSERT INTO food600.eany(c_karty, ean, popis, koef, c_data, objem, idriadok_master)
								SELECT c_karty, ean, popis, koef, c_data, objem, idriadok as idriadok_master FROM dblink('connstrx','SELECT c_karty, ean, popis, koef, c_data, idriadok, objem FROM food600.eany ORDER BY idriadok') 
								as remzmeny(c_karty BIGINT, ean CHARACTER(30), popis CHARACTER(50), koef NUMERIC(10,4), c_data INTEGER, idriadok INTEGER, objem NUMERIC(10,4)) ;
							ALTER TABLE food600.eany ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.eany;
							SELECT nextval('food600.eany_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.eany_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.eany_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='users' THEN
							ALTER TABLE food600.users DISABLE TRIGGER ALL;
							TRUNCATE food600.users RESTART IDENTITY;
							INSERT INTO food600.users(heslo, username, user_id, jazyk, hash, hashfood, hashoman, mzda, idriadok, is_admin, user_ean, hashfoodie, hashfoodie2, hashfoodie3, idriadok_master)
								SELECT heslo, username, user_id, jazyk, hash, hashfood, hashoman, mzda, idriadok, is_admin, user_ean, hashfoodie, hashfoodie2, hashfoodie3, idriadok as idriadok_master FROM dblink('connstrx','SELECT heslo, username, user_id, jazyk, hash, hashfood, hashoman, mzda, idriadok, is_admin, user_ean, hashfoodie, hashfoodie2, hashfoodie3 FROM food600.users ORDER BY idriadok') 
								as remzmeny(heslo CHARACTER(12), username CHARACTER(15), user_id CHARACTER(3), jazyk CHARACTER(1), hash CHARACTER(12), hashfood CHARACTER(12), hashoman CHARACTER(12), mzda numeric(20,10), idriadok INTEGER, is_admin SMALLINT, user_ean CHARACTER(13), hashfoodie CHARACTER(100), hashfoodie2 CHARACTER(100), hashfoodie3 CHARACTER(100)) ;
							ALTER TABLE food600.users ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.users;
							SELECT nextval('food600.users_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.users_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.users_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='ug___' THEN
							ALTER TABLE food600.ug___ DISABLE TRIGGER ALL;
							TRUNCATE food600.ug___ RESTART IDENTITY;
							INSERT INTO food600.ug___(user_id, id, modul, g0, g1, g2, g3, g4, g5, g6, g7, g8, g9, idriadok, idriadok_master)
								SELECT user_id, id, modul, g0, g1, g2, g3, g4, g5, g6, g7, g8, g9, idriadok, idriadok as idriadok_master FROM dblink('connstrx','SELECT user_id, id, modul, g0, g1, g2, g3, g4, g5, g6, g7, g8, g9, idriadok FROM food600.ug___ ORDER BY idriadok') 
								as remzmeny(user_id CHARACTER(3), id CHARACTER(2), modul CHARACTER(12), g0 SMALLINT, g1 SMALLINT, g2 SMALLINT, g3 SMALLINT, g4 SMALLINT, g5 SMALLINT, g6 SMALLINT, g7 SMALLINT, g8 SMALLINT, g9 SMALLINT, idriadok INTEGER) ;
							ALTER TABLE food600.ug___ ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.ug___;
							SELECT nextval('food600.ug____idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.ug____idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.ug____idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='gr___' THEN
							ALTER TABLE food600.gr___ DISABLE TRIGGER ALL;
							TRUNCATE food600.gr___ RESTART IDENTITY;
							INSERT INTO food600.gr___(klic, g0, g1, g2, g3, g4, g5, g6, g7, g8, g9, idriadok, modul, idriadok_master)
								SELECT klic, g0, g1, g2, g3, g4, g5, g6, g7, g8, g9, idriadok, modul, idriadok as idriadok_master FROM dblink('connstrx','SELECT klic, g0, g1, g2, g3, g4, g5, g6, g7, g8, g9, idriadok, modul FROM food600.gr___ ORDER BY idriadok') 
								as remzmeny(klic CHARACTER(30), g0 SMALLINT, g1 SMALLINT, g2 SMALLINT, g3 SMALLINT, g4 SMALLINT, g5 SMALLINT, g6 SMALLINT, g7 SMALLINT, g8 SMALLINT, g9 SMALLINT, idriadok INTEGER, modul CHARACTER(12)) ;
							ALTER TABLE food600.gr___ ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.gr___;
							SELECT nextval('food600.gr____idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.gr____idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.gr____idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='defsubor' THEN
							ALTER TABLE food600.defsubor DISABLE TRIGGER ALL;
							TRUNCATE food600.defsubor RESTART IDENTITY;
							INSERT INTO food600.defsubor(var_name, var_value, modul, setup_skup, idriadok, idriadok_master)
								SELECT var_name, var_value, modul, setup_skup, idriadok, idriadok as idriadok_master FROM dblink('connstrx','SELECT var_name, var_value, modul, setup_skup, idriadok FROM food600.defsubor ORDER BY idriadok') 
								as remzmeny(var_name CHARACTER(50), var_value CHARACTER(111), modul CHARACTER(12), setup_skup CHARACTER(2), idriadok INTEGER) ;
							ALTER TABLE food600.defsubor ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.defsubor;
							SELECT nextval('food600.defsubor_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.defsubor_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.defsubor_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='sk__fin' THEN
							ALTER TABLE food600.sk__fin DISABLE TRIGGER ALL;
							TRUNCATE food600.sk__fin RESTART IDENTITY;
							INSERT INTO food600.sk__fin(c_uzaverka, ucet, autor, u_cas, u_minut, mutace, cas_atrib, pocet_h, stul, text_sleva, text_link, ducis, lim_datum, id_limit, round50, pohladavka, c_data, idriadok, id_den, id_chod, id_slave, id_miestnost, u_datetime, loyalman, c_uzav_cis, idriadok_master)
								SELECT c_uzaverka, ucet, autor, u_cas, u_minut, mutace, cas_atrib, pocet_h, stul, text_sleva, text_link, ducis, lim_datum, id_limit, round50, pohladavka, c_data, idriadok, id_den, id_chod, id_slave, id_miestnost, u_datetime, loyalman, c_uzav_cis, idriadok as idriadok_master FROM dblink('connstrx','SELECT c_uzaverka, ucet, autor, u_cas, u_minut, mutace, cas_atrib, pocet_h, stul, text_sleva, text_link, ducis, lim_datum, id_limit, round50, pohladavka, c_data, idriadok, id_den, id_chod, id_slave, id_miestnost, u_datetime, loyalman, c_uzav_cis FROM food600.sk__fin ORDER BY idriadok') 
								as remzmeny(c_uzaverka INTEGER, ucet INTEGER, autor CHARACTER(3), u_cas CHARACTER(8), u_minut NUMERIC(4,0), mutace CHARACTER(1), cas_atrib CHARACTER(1), pocet_h NUMERIC(4,0), stul NUMERIC(6,1), text_sleva CHARACTER(16), text_link CHARACTER(25), ducis CHARACTER(4), lim_datum DATE, id_limit INTEGER, round50 NUMERIC(4,2), pohladavka SMALLINT, c_data INTEGER, idriadok INTEGER, id_den INTEGER, id_chod INTEGER, id_slave CHARACTER(2), id_miestnost INTEGER, u_datetime TIMESTAMP WITHOUT TIME ZONE, loyalman UUID, c_uzav_cis INTEGER) ;
							ALTER TABLE food600.sk__fin ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.sk__fin;
							SELECT nextval('food600.sk__fin_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.sk__fin_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.sk__fin_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='sk__fis' THEN
							ALTER TABLE food600.sk__fis DISABLE TRIGGER ALL;
							TRUNCATE food600.sk__fis RESTART IDENTITY;
							INSERT INTO food600.sk__fis(ucet, c_uzaverka, fucis, fuciarkod, fuzcislo, fuzdate, idriadok, c_data, nedokonceny, prn_no, okp, uid, idriadok_master)
								SELECT ucet, c_uzaverka, fucis, fuciarkod, fuzcislo, fuzdate, idriadok, c_data, nedokonceny, prn_no, okp, uid, idriadok as idriadok_master FROM dblink('connstrx','SELECT ucet, c_uzaverka, fucis, fuciarkod, fuzcislo, fuzdate, idriadok, c_data, nedokonceny, prn_no, okp, uid FROM food600.sk__fis ORDER BY idriadok') 
								as remzmeny(ucet INTEGER, c_uzaverka INTEGER, fucis INTEGER, fuciarkod CHARACTER(20), fuzcislo INTEGER, fuzdate DATE, idriadok INTEGER, c_data INTEGER, nedokonceny SMALLINT, prn_no CHARACTER(2), okp CHARACTER(45), uid CHARACTER(52)) ;
							ALTER TABLE food600.sk__fis ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.sk__fis;
							SELECT nextval('food600.sk__fis_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.sk__fis_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.sk__fis_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='sk__pol' THEN
							ALTER TABLE food600.sk__pol DISABLE TRIGGER ALL;
							TRUNCATE food600.sk__pol RESTART IDENTITY;
							INSERT INTO food600.sk__pol(c_uzaverka, ucet, c_stredisk, c_karty, prachy, prachy_puv, dan, dan_sazba, mnozstvi, cen_hlad, k_odpoctu, poradi, dotacia, dil_porce, id_fmenu, c_data, idriadok, kompez, stor_mno, id_karty, sleva_pol, sleva_txt, jc, id_rov, idriadok_master)
								SELECT c_uzaverka, ucet, c_stredisk, c_karty, prachy, prachy_puv, dan, dan_sazba, mnozstvi, cen_hlad, k_odpoctu, poradi, dotacia, dil_porce, id_fmenu, c_data, idriadok, kompez, stor_mno, id_karty, sleva_pol, sleva_txt, jc, id_rov, idriadok as idriadok_master FROM dblink('connstrx','SELECT c_uzaverka, ucet, c_stredisk, c_karty, prachy, prachy_puv, dan, dan_sazba, mnozstvi, cen_hlad, k_odpoctu, poradi, dotacia, dil_porce, id_fmenu, c_data, idriadok, kompez, stor_mno, id_karty, sleva_pol, sleva_txt, jc, id_rov FROM food600.sk__pol ORDER BY idriadok') 
								as remzmeny(c_uzaverka INTEGER, ucet INTEGER, c_stredisk INTEGER, c_karty INTEGER, prachy NUMERIC(10,2), prachy_puv NUMERIC(10,2), dan NUMERIC(9,2), dan_sazba NUMERIC(4,1), mnozstvi NUMERIC(10,3), cen_hlad CHARACTER(2), k_odpoctu CHARACTER(1), poradi INTEGER, dotacia CHARACTER(1), dil_porce NUMERIC(1,0), id_fmenu CHARACTER(7), c_data INTEGER, idriadok INTEGER, kompez SMALLINT, stor_mno NUMERIC(10,3), id_karty INTEGER, sleva_pol NUMERIC(10,2), sleva_txt CHARACTER VARYING(20), jc NUMERIC(12,2), id_rov INTEGER) ;
							ALTER TABLE food600.sk__pol ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.sk__pol;
							SELECT nextval('food600.sk__pol_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.sk__pol_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.sk__pol_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='sk__plt' THEN
							ALTER TABLE food600.sk__plt DISABLE TRIGGER ALL;
							TRUNCATE food600.sk__plt RESTART IDENTITY;
							INSERT INTO food600.sk__plt(c_uzaverka, ucet, druh_pl, cena_pl, tip, mena, cena_mena, poradi, text, c_data, idriadok, kompez, fik, bkp, cas_odesl, preplatok, referencia, cena_real, idriadok_master)
								SELECT c_uzaverka, ucet, druh_pl, cena_pl, tip, mena, cena_mena, poradi, text, c_data, idriadok, kompez, fik, bkp, cas_odesl, preplatok, referencia, cena_real, idriadok as idriadok_master FROM dblink('connstrx','SELECT c_uzaverka, ucet, druh_pl, cena_pl, tip, mena, cena_mena, poradi, text, c_data, idriadok, kompez, fik, bkp, cas_odesl, preplatok, referencia, cena_real FROM food600.sk__plt ORDER BY idriadok') 
								as remzmeny(c_uzaverka INTEGER, ucet INTEGER, druh_pl CHARACTER(10), cena_pl NUMERIC(12,2), tip NUMERIC(10,2), mena CHARACTER(3), cena_mena NUMERIC(12,2), poradi NUMERIC(2,0), text CHARACTER(30), c_data INTEGER, idriadok INTEGER, kompez SMALLINT, fik CHARACTER VARYING(39), bkp CHARACTER VARYING(44), cas_odesl CHARACTER VARYING(13), preplatok NUMERIC(12,2), referencia INTEGER, cena_real NUMERIC(12,2)) ;
							ALTER TABLE food600.sk__plt ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.sk__plt;
							SELECT nextval('food600.sk__plt_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.sk__plt_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.sk__plt_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='sk__txt' THEN
							ALTER TABLE food600.sk__txt DISABLE TRIGGER ALL;
							TRUNCATE food600.sk__txt RESTART IDENTITY;
							INSERT INTO food600.sk__txt(ucet, c_uzaverka, poradi, txt, jmeno, adresa1, adresa2, adresa3, schvalil, akce, dic, cislo, hucet, hpokoj, hjmeno, hporad, hpref, hid, icdph, ico, c_data, idriadok, info, idriadok_master)
								SELECT ucet, c_uzaverka, poradi, txt, jmeno, adresa1, adresa2, adresa3, schvalil, akce, dic, cislo, hucet, hpokoj, hjmeno, hporad, hpref, hid, icdph, ico, c_data, idriadok, info, idriadok as idriadok_master FROM dblink('connstrx','SELECT ucet, c_uzaverka, poradi, txt, jmeno, adresa1, adresa2, adresa3, schvalil, akce, dic, cislo, hucet, hpokoj, hjmeno, hporad, hpref, hid, icdph, ico, c_data, idriadok, info FROM food600.sk__txt ORDER BY idriadok') 
								as remzmeny(ucet INTEGER, c_uzaverka INTEGER, poradi NUMERIC(4,0), txt CHARACTER(35), jmeno CHARACTER(35), adresa1 CHARACTER(35), adresa2 CHARACTER(35), adresa3 CHARACTER(35), schvalil CHARACTER(35), akce CHARACTER(35), dic CHARACTER(15), cislo CHARACTER(15), hucet CHARACTER(15), hpokoj CHARACTER(6), hjmeno CHARACTER(40), hporad CHARACTER(40), hpref CHARACTER(15), hid CHARACTER(15), icdph CHARACTER(20), ico CHARACTER(15), c_data INTEGER, idriadok INTEGER, info JSONB) ;
							ALTER TABLE food600.sk__txt ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.sk__txt;
							SELECT nextval('food600.sk__txt_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.sk__txt_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.sk__txt_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='sk__sez' THEN
							ALTER TABLE food600.sk__sez DISABLE TRIGGER ALL;
							TRUNCATE food600.sk__sez RESTART IDENTITY;
							INSERT INTO food600.sk__sez(c_kas, id_kas, c_stredisk, id_man, uzaverka, c_uzaverka, c_uzav_kas, autor, odecteno, uz_cislo, uctexport, c_mena, priznak, c_data, idriadok, uct_den, lastuzav, idriadok_master)
								SELECT c_kas, id_kas, c_stredisk, id_man, uzaverka, c_uzaverka, c_uzav_kas, autor, odecteno, uz_cislo, uctexport, c_mena, priznak, c_data, idriadok, uct_den, lastuzav, idriadok as idriadok_master FROM dblink('connstrx','SELECT c_kas, id_kas, c_stredisk, id_man, uzaverka, c_uzaverka, c_uzav_kas, autor, odecteno, uz_cislo, uctexport, c_mena, priznak, c_data, idriadok, uct_den, lastuzav FROM food600.sk__sez ORDER BY idriadok') 
								as remzmeny(c_kas INTEGER, id_kas CHARACTER(2), c_stredisk INTEGER, id_man CHARACTER(2), uzaverka CHARACTER(17), c_uzaverka INTEGER, c_uzav_kas INTEGER, autor CHARACTER(3), odecteno SMALLINT, uz_cislo INTEGER, uctexport SMALLINT, c_mena INTEGER, priznak CHARACTER(20), c_data INTEGER, idriadok INTEGER, uct_den DATE, lastuzav CHARACTER(17)) ;
							ALTER TABLE food600.sk__sez ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.sk__sez;
							SELECT nextval('food600.sk__sez_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.sk__sez_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.sk__sez_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='sk__vklvy' THEN
							ALTER TABLE food600.sk__vklvy DISABLE TRIGGER ALL;
							TRUNCATE food600.sk__vklvy RESTART IDENTITY;
							INSERT INTO food600.sk__vklvy(nazev, datum, c_uzaverka, ucet, ciastka, mena, ciast_mena, autor, cisfplat, popis, fciarkod, fucis, komu, operacia, idriadok, c_data, idriadok_master)
								SELECT nazev, datum, c_uzaverka, ucet, ciastka, mena, ciast_mena, autor, cisfplat, popis, fciarkod, fucis, komu, operacia, idriadok, c_data, idriadok as idriadok_master FROM dblink('connstrx','SELECT nazev, datum, c_uzaverka, ucet, ciastka, mena, ciast_mena, autor, cisfplat, popis, fciarkod, fucis, komu, operacia, idriadok, c_data FROM food600.sk__vklvy ORDER BY idriadok') 
								as remzmeny(nazev CHARACTER(8), datum TIMESTAMP WITHOUT TIME ZONE, c_uzaverka INTEGER, ucet INTEGER, ciastka NUMERIC(12,2), mena CHARACTER(3), ciast_mena NUMERIC(12,2), autor CHARACTER(3), cisfplat NUMERIC(2,0), popis CHARACTER(50), fciarkod CHARACTER(20), fucis INTEGER, komu CHARACTER(3), operacia NUMERIC(1,0), idriadok INTEGER, c_data INTEGER) ;
							ALTER TABLE food600.sk__vklvy ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.sk__vklvy;
							SELECT nextval('food600.sk__vklvy_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.sk__vklvy_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.sk__vklvy_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='sk__uza' THEN
							ALTER TABLE food600.sk__uza DISABLE TRIGGER ALL;
							TRUNCATE food600.sk__uza RESTART IDENTITY;
							INSERT INTO food600.sk__uza(idriadok, uzaverka, c_data, id_kas, rep_uzaverka, fuzcislo, rk_rep, idriadok_master)
								SELECT idriadok, uzaverka, c_data, id_kas, rep_uzaverka, fuzcislo, rk_rep, idriadok as idriadok_master FROM dblink('connstrx','SELECT idriadok, uzaverka, c_data, id_kas, rep_uzaverka, fuzcislo, rk_rep FROM food600.sk__uza ORDER BY idriadok') 
								as remzmeny(idriadok INTEGER, uzaverka CHARACTER(17), c_data INTEGER, id_kas CHARACTER(2), rep_uzaverka JSONB, fuzcislo INTEGER, rk_rep TEXT) ;
							ALTER TABLE food600.sk__uza ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.sk__uza;
							SELECT nextval('food600.sk__uza_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.sk__uza_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.sk__uza_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='sk__uza_cis' THEN
							ALTER TABLE food600.sk__uza_cis DISABLE TRIGGER ALL;
							TRUNCATE food600.sk__uza_cis RESTART IDENTITY;
							INSERT INTO food600.sk__uza_cis(idriadok, uzaverka, c_data, id_kas, rep_uzaverka, fuzcislo, autor, casnik, idriadok_master)
								SELECT idriadok, uzaverka, c_data, id_kas, rep_uzaverka, fuzcislo, autor, casnik, idriadok as idriadok_master FROM dblink('connstrx','SELECT idriadok, uzaverka, c_data, id_kas, rep_uzaverka, fuzcislo, autor, casnik FROM food600.sk__uza_cis ORDER BY idriadok') 
								as remzmeny(idriadok INTEGER, uzaverka CHARACTER(17), c_data INTEGER, id_kas CHARACTER(2), rep_uzaverka JSONB, fuzcislo INTEGER, autor CHARACTER(3), casnik CHARACTER(3)) ;
							ALTER TABLE food600.sk__uza_cis ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.sk__uza_cis;
							SELECT nextval('food600.sk__uza_cis_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.sk__uza_cis_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.sk__uza_cis_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='nlimit_hl' THEN
							ALTER TABLE food600.nlimit_hl DISABLE TRIGGER ALL;
							TRUNCATE food600.nlimit_hl RESTART IDENTITY;
							INSERT INTO food600.nlimit_hl(id_limit, menolimit, id_typ, is_kasy, txt_kasy, c_kasy, hladina, txt1, txt2, hladina1, hladina2, zlava, typ_zlavy, poznamka, pozn_int, c_mena, archiv, c_data, zmazane, kontakt, kontakt1, prichod, firma, c_partner, adr1, adr2, adr3, adr4, id_stat, typ_pohybu, id_limit_master)
								SELECT id_limit, menolimit, id_typ, is_kasy, txt_kasy, c_kasy, hladina, txt1, txt2, hladina1, hladina2, zlava, typ_zlavy, poznamka, pozn_int, c_mena, archiv, c_data, zmazane, kontakt, kontakt1, prichod, firma, c_partner, adr1, adr2, adr3, adr4, id_stat, typ_pohybu, id_limit as id_limit_master FROM dblink('connstrx','SELECT id_limit, menolimit, id_typ, is_kasy, txt_kasy, c_kasy, hladina, txt1, txt2, hladina1, hladina2, zlava, typ_zlavy, poznamka, pozn_int, c_mena, archiv, c_data, zmazane, kontakt, kontakt1, prichod, firma, c_partner, adr1, adr2, adr3, adr4, id_stat, typ_pohybu FROM food600.nlimit_hl ORDER BY id_limit') 
								as remzmeny(id_limit INTEGER, menolimit CHARACTER(50), id_typ INTEGER, is_kasy SMALLINT, txt_kasy CHARACTER(20), c_kasy INTEGER, hladina CHARACTER(2), txt1 CHARACTER(70), txt2 CHARACTER(70), hladina1 CHARACTER(30), hladina2 CHARACTER(30), zlava NUMERIC(10,2), typ_zlavy CHARACTER(1), poznamka TEXT, pozn_int TEXT, c_mena SMALLINT, archiv SMALLINT, c_data INTEGER, zmazane SMALLINT, kontakt CHARACTER(30), kontakt1 CHARACTER(30), prichod CHARACTER(30), firma CHARACTER(30), c_partner INTEGER, adr1 CHARACTER(30), adr2 CHARACTER(30), adr3 CHARACTER(30), adr4 CHARACTER(30), id_stat INTEGER, typ_pohybu SMALLINT) ;
							ALTER TABLE food600.nlimit_hl ENABLE TRIGGER ALL;
							SELECT MAX(id_limit) into maxid FROM food600.nlimit_hl;
							SELECT nextval('food600.nlimit_hl_id_limit_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.nlimit_hl_id_limit_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.nlimit_hl_id_limit_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='nlimitchody' THEN
							ALTER TABLE food600.nlimitchody DISABLE TRIGGER ALL;
							TRUNCATE food600.nlimitchody RESTART IDENTITY;
							INSERT INTO food600.nlimitchody(id_chod, chod, chod1, chod2, chod3, zmazane, c_data, id_chod_master)
								SELECT id_chod, chod, chod1, chod2, chod3, zmazane, c_data, id_chod as id_chod_master FROM dblink('connstrx','SELECT id_chod, chod, chod1, chod2, chod3, zmazane, c_data FROM food600.nlimitchody ORDER BY id_chod') 
								as remzmeny(id_chod INTEGER, chod CHARACTER(50), chod1 CHARACTER(50), chod2 CHARACTER(50), chod3 CHARACTER(50), zmazane SMALLINT, c_data INTEGER) ;
							ALTER TABLE food600.nlimitchody ENABLE TRIGGER ALL;
							SELECT MAX(id_chod) into maxid FROM food600.nlimitchody;
							SELECT nextval('food600.nlimitchody_id_chod_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.nlimitchody_id_chod_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.nlimitchody_id_chod_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='nlimittypy' THEN
							ALTER TABLE food600.nlimittypy DISABLE TRIGGER ALL;
							TRUNCATE food600.nlimittypy RESTART IDENTITY;
							INSERT INTO food600.nlimittypy(id_typ, menotyp, zmazane, c_data, hk_typ, id_typ_master)
								SELECT id_typ, menotyp, zmazane, c_data, hk_typ, id_typ as id_typ_master FROM dblink('connstrx','SELECT id_typ, menotyp, zmazane, c_data, hk_typ FROM food600.nlimittypy ORDER BY id_typ') 
								as remzmeny(id_typ INTEGER, menotyp CHARACTER(30), zmazane SMALLINT, c_data INTEGER, hk_typ CHARACTER(1)) ;
							ALTER TABLE food600.nlimittypy ENABLE TRIGGER ALL;
							SELECT MAX(id_typ) into maxid FROM food600.nlimittypy;
							SELECT nextval('food600.nlimittypy_id_typ_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.nlimittypy_id_typ_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.nlimittypy_id_typ_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='nlimittypchody' THEN
							ALTER TABLE food600.nlimittypchody DISABLE TRIGGER ALL;
							TRUNCATE food600.nlimittypchody RESTART IDENTITY;
							INSERT INTO food600.nlimittypchody(id_typ, id_chod, idriadok, c_data, poradie, posledny, idriadok_master)
								SELECT id_typ, id_chod, idriadok, c_data, poradie, posledny, idriadok as idriadok_master FROM dblink('connstrx','SELECT id_typ, id_chod, idriadok, c_data, poradie, posledny FROM food600.nlimittypchody ORDER BY idriadok') 
								as remzmeny(id_typ INTEGER, id_chod INTEGER, idriadok INTEGER, c_data INTEGER, poradie INTEGER, posledny SMALLINT) ;
							ALTER TABLE food600.nlimittypchody ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.nlimittypchody;
							SELECT nextval('food600.nlimittypchody_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.nlimittypchody_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.nlimittypchody_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='nlimitdni' THEN
							ALTER TABLE food600.nlimitdni DISABLE TRIGGER ALL;
							TRUNCATE food600.nlimitdni RESTART IDENTITY;
							INSERT INTO food600.nlimitdni(id_limit, id_den, datum, c_data, c_mena, id_den_master)
								SELECT id_limit, id_den, datum, c_data, c_mena,id_den as id_den_master FROM dblink('connstrx','SELECT id_limit, id_den, datum, c_data, c_mena FROM food600.nlimitdni ORDER BY id_den') 
								as remzmeny(id_limit INTEGER, id_den INTEGER, datum DATE, c_data INTEGER, c_mena SMALLINT) ;
							ALTER TABLE food600.nlimitdni ENABLE TRIGGER ALL;
							SELECT MAX(id_den) into maxid FROM food600.nlimitdni;
							SELECT nextval('food600.nlimitdni_id_den_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.nlimitdni_id_den_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.nlimitdni_id_den_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='nlimitrov' THEN
							ALTER TABLE food600.nlimitrov DISABLE TRIGGER ALL;
							TRUNCATE food600.nlimitrov RESTART IDENTITY;
							INSERT INTO food600.nlimitrov(id_limit, id_den, id_rov, id_chod, limit1, limit2, poznamka, pozn_int, c_kasy, hladina, txt1, txt2, poradie, label, c_data, pocet1, pocet2, uzaverka, u_cis, cenhlad, zlava, c_dokl, id_rov_master)
								SELECT id_limit, id_den, id_rov, id_chod, limit1, limit2, poznamka, pozn_int, c_kasy, hladina, txt1, txt2, poradie, label, c_data, pocet1, pocet2, uzaverka, u_cis, cenhlad, zlava, c_dokl, id_rov as id_rov_master FROM dblink('connstrx','SELECT id_limit, id_den, id_rov, id_chod, limit1, limit2, poznamka, pozn_int, c_kasy, hladina, txt1, txt2, poradie, label, c_data, pocet1, pocet2, uzaverka, u_cis, cenhlad, zlava, c_dokl FROM food600.nlimitrov ORDER BY id_rov') 
								as remzmeny(id_limit INTEGER, id_den INTEGER, id_rov INTEGER, id_chod INTEGER, limit1 numeric(20,10), limit2 numeric(20,10), poznamka TEXT, pozn_int TEXT, c_kasy INTEGER, hladina CHARACTER(2), txt1 CHARACTER(30), txt2 CHARACTER(30), poradie SMALLINT, label SMALLINT, c_data INTEGER, pocet1 numeric(20,10), pocet2 numeric(20,10), uzaverka CHARACTER(17), u_cis CHARACTER(7), cenhlad CHARACTER(2), zlava NUMERIC(6,2), c_dokl INTEGER) ;
							ALTER TABLE food600.nlimitrov ENABLE TRIGGER ALL;
							SELECT MAX(id_rov) into maxid FROM food600.nlimitrov;
							SELECT nextval('food600.nlimitrov_id_rov_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.nlimitrov_id_rov_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.nlimitrov_id_rov_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='nlimity' THEN
							ALTER TABLE food600.nlimity DISABLE TRIGGER ALL;
							TRUNCATE food600.nlimity RESTART IDENTITY;
							INSERT INTO food600.nlimity(id_limit, id_den, id_rov, c_karty, cena_prod, dan, mnozstvi, poradie, c_stredisk, poznamka, vlastnik, label, idriadok, c_data, nc, dieta, vyber, zlava, id_fmenu, mnoz_ori, idriadok_master)
								SELECT id_limit, id_den, id_rov, c_karty, cena_prod, dan, mnozstvi, poradie, c_stredisk, poznamka, vlastnik, label, idriadok, c_data, nc, dieta, vyber, zlava, id_fmenu, mnoz_ori, idriadok as idriadok_master FROM dblink('connstrx','SELECT id_limit, id_den, id_rov, c_karty, cena_prod, dan, mnozstvi, poradie, c_stredisk, poznamka, vlastnik, label, idriadok, c_data, nc, dieta, vyber, zlava, id_fmenu, mnoz_ori FROM food600.nlimity ORDER BY idriadok') 
								as remzmeny(id_limit INTEGER, id_den INTEGER, id_rov INTEGER, c_karty INTEGER, cena_prod numeric(20,10), dan NUMERIC(4,2), mnozstvi numeric(20,10), poradie SMALLINT, c_stredisk INTEGER, poznamka CHARACTER(30), vlastnik CHARACTER(2), label SMALLINT, idriadok INTEGER, c_data INTEGER, nc numeric(20,10), dieta CHARACTER(5), vyber CHARACTER(5), zlava NUMERIC(6,2), id_fmenu CHARACTER(7), mnoz_ori  numeric(20,10)) ;
							ALTER TABLE food600.nlimity ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.nlimity;
							SELECT nextval('food600.nlimity_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.nlimity_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.nlimity_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='nlimitsablonyhl' THEN
							ALTER TABLE food600.nlimitsablonyhl DISABLE TRIGGER ALL;
							TRUNCATE food600.nlimitsablonyhl RESTART IDENTITY;
							INSERT INTO food600.nlimitsablonyhl(id_limit, menolimit, id_typ, pocetdni, c_data, id_chod, id_limit_master)
								SELECT id_limit, menolimit, id_typ, pocetdni, c_data, id_chod, id_limit as id_limit_master FROM dblink('connstrx','SELECT id_limit, menolimit, id_typ, pocetdni, c_data, id_chod FROM food600.nlimitsablonyhl ORDER BY id_limit') 
								as remzmeny(id_limit INTEGER, menolimit CHARACTER(50), id_typ INTEGER, pocetdni INTEGER, c_data INTEGER, id_chod INTEGER) ;
							ALTER TABLE food600.nlimitsablonyhl ENABLE TRIGGER ALL;
							SELECT MAX(id_limit) into maxid FROM food600.nlimitsablonyhl;
							SELECT nextval('food600.nlimitsablonyhl_id_limit_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.nlimitsablonyhl_id_limit_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.nlimitsablonyhl_id_limit_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='nlimitsablonydni' THEN
							ALTER TABLE food600.nlimitsablonydni DISABLE TRIGGER ALL;
							TRUNCATE food600.nlimitsablonydni RESTART IDENTITY;
							INSERT INTO food600.nlimitsablonydni(id_limit, cyklus, den, id_den, c_data, id_chod, limit1, limit2, pocet1, pocet2, poznamka, pozn_int, id_den_master)
								SELECT id_limit, cyklus, den, id_den, c_data, id_chod, limit1, limit2, pocet1, pocet2, poznamka, pozn_int, id_den as id_den_master FROM dblink('connstrx','SELECT id_limit, cyklus, den, id_den, c_data, id_chod, limit1, limit2, pocet1, pocet2, poznamka, pozn_int FROM food600.nlimitsablonydni ORDER BY id_den') 
								as remzmeny(id_limit INTEGER, cyklus INTEGER, den INTEGER, id_den INTEGER, c_data INTEGER, id_chod INTEGER, limit1 numeric(20,10), limit2 numeric(20,10), pocet1 NUMERIC(5,0), pocet2 NUMERIC(5,0), poznamka CHARACTER VARYING(250), pozn_int CHARACTER VARYING(250)) ;
							ALTER TABLE food600.nlimitsablonydni ENABLE TRIGGER ALL;
							SELECT MAX(id_den) into maxid FROM food600.nlimitsablonydni;
							SELECT nextval('food600.nlimitsablonydni_id_den_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.nlimitsablonydni_id_den_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.nlimitsablonydni_id_den_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='nlimitsablonypol' THEN
							ALTER TABLE food600.nlimitsablonypol DISABLE TRIGGER ALL;
							TRUNCATE food600.nlimitsablonypol RESTART IDENTITY;
							INSERT INTO food600.nlimitsablonypol(id_limit, id_den, c_karty, cena_prod, dan, mnozstvi, poradie, c_stredisk, poznamka, vlastnik, nc, label, dieta, vyber, idriadok, c_data, id_fmenu, idriadok_master)
								SELECT id_limit, id_den, c_karty, cena_prod, dan, mnozstvi, poradie, c_stredisk, poznamka, vlastnik, nc, label, dieta, vyber, idriadok, c_data, id_fmenu, idriadok as idriadok_master FROM dblink('connstrx','SELECT id_limit, id_den, c_karty, cena_prod, dan, mnozstvi, poradie, c_stredisk, poznamka, vlastnik, nc, label, dieta, vyber, idriadok, c_data, id_fmenu FROM food600.nlimitsablonypol ORDER BY idriadok') 
								as remzmeny(id_limit INTEGER, id_den INTEGER, c_karty INTEGER, cena_prod numeric(20,10), dan NUMERIC(5,3), mnozstvi numeric(20,10), poradie INTEGER, c_stredisk INTEGER, poznamka CHARACTER(30), vlastnik CHARACTER(2), nc numeric(20,10), label SMALLINT, dieta CHARACTER(5), vyber CHARACTER(5), idriadok INTEGER, c_data INTEGER, id_fmenu CHARACTER(7)) ;
							ALTER TABLE food600.nlimitsablonypol ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.nlimitsablonypol;
							SELECT nextval('food600.nlimitsablonzpol_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.nlimitsablonzpol_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.nlimitsablonzpol_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='nlimitstatus' THEN
							ALTER TABLE food600.nlimitstatus DISABLE TRIGGER ALL;
							TRUNCATE food600.nlimitstatus RESTART IDENTITY;
							INSERT INTO food600.nlimitstatus(id_stat, status, zmazane, c_data, start, koniec, stat_eshop, farba, id_stat_master)
								SELECT id_stat, status, zmazane, c_data, start, koniec, stat_eshop, farba, id_stat as id_stat_master FROM dblink('connstrx','SELECT id_stat, status, zmazane, c_data, start, koniec, stat_eshop, farba FROM food600.nlimitstatus ORDER BY id_stat') 
								as remzmeny(id_stat INTEGER, status CHARACTER(30), zmazane SMALLINT, c_data SMALLINT, start SMALLINT, koniec SMALLINT, stat_eshop SMALLINT, farba INTEGER) ;
							ALTER TABLE food600.nlimitstatus ENABLE TRIGGER ALL;
							SELECT MAX(id_stat) into maxid FROM food600.nlimitstatus;
							SELECT nextval('food600.nlimitstatus_id_stat_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.nlimitstatus_id_stat_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.nlimitstatus_id_stat_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='nlimitstrava' THEN
							ALTER TABLE food600.nlimitstrava DISABLE TRIGGER ALL;
							TRUNCATE food600.nlimitstrava RESTART IDENTITY;
							INSERT INTO food600.nlimitstrava(id_strav, id_limit, id_den, id_rov, pocet, c_data, idriadok, idriadok_master)
								SELECT id_strav, id_limit, id_den, id_rov, pocet, c_data, idriadok, idriadok as idriadok_master FROM dblink('connstrx','SELECT id_strav, id_limit, id_den, id_rov, pocet, c_data, idriadok FROM food600.nlimitstrava ORDER BY idriadok') 
								as remzmeny(id_strav INTEGER, id_limit INTEGER, id_den INTEGER, id_rov INTEGER, pocet SMALLINT, c_data SMALLINT, idriadok INTEGER) ;
							ALTER TABLE food600.nlimitstrava ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.nlimitstrava;
							SELECT nextval('food600.nlimitstrava_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.nlimitstrava_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.nlimitstrava_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='nlimitstravnici' THEN
							ALTER TABLE food600.nlimitstravnici DISABLE TRIGGER ALL;
							TRUNCATE food600.nlimitstravnici RESTART IDENTITY;
							INSERT INTO food600.nlimitstravnici(id_strav, priezvisko, meno, oscislo, stredisko, zmazane, c_data, id_strav_master)
								SELECT id_strav, priezvisko, meno, oscislo, stredisko, zmazane, c_data, id_strav as id_strav_master FROM dblink('connstrx','SELECT id_strav, priezvisko, meno, oscislo, stredisko, zmazane, c_data FROM food600.nlimitstravnici ORDER BY id_strav') 
								as remzmeny(id_strav INTEGER, priezvisko CHARACTER(30), meno CHARACTER(30), oscislo CHARACTER(20), stredisko CHARACTER(30), zmazane SMALLINT, c_data SMALLINT) ;
							ALTER TABLE food600.nlimitstravnici ENABLE TRIGGER ALL;
							SELECT MAX(id_strav) into maxid FROM food600.nlimitstravnici;
							SELECT nextval('food600.nlimitstravnici_id_strav_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.nlimitstravnici_id_strav_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.nlimitstravnici_id_strav_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='partneri' THEN
							ALTER TABLE food600.partneri DISABLE TRIGGER ALL;
							TRUNCATE food600.partneri RESTART IDENTITY;
							INSERT INTO food600.partneri(c_partner, partner, ico, dic, banka, ucet, telefon, naz1, naz2, naz3, naz4, naz5, naz6, splatnost, cen_hlad, sleva_proc, c_data, idriadok, icdph, alkokod, ext_id, ext_intern, platcadph, zmena, edi_kod, typ_obj, edi_mankod, platba, email, popis, idriadok_master)
								SELECT c_partner, partner, ico, dic, banka, ucet, telefon, naz1, naz2, naz3, naz4, naz5, naz6, splatnost, cen_hlad, sleva_proc, c_data, idriadok, icdph, alkokod, ext_id, ext_intern, platcadph, zmena, edi_kod, typ_obj, edi_mankod, platba, email, popis, idriadok as idriadok_master FROM dblink('connstrx','SELECT c_partner, partner, ico, dic, banka, ucet, telefon, naz1, naz2, naz3, naz4, naz5, naz6, splatnost, cen_hlad, sleva_proc, c_data, idriadok, icdph, alkokod, ext_id, ext_intern, platcadph, zmena, edi_kod, typ_obj, edi_mankod, platba, email, popis FROM food600.partneri ORDER BY idriadok') 
								as remzmeny(c_partner INTEGER, partner CHARACTER(30), ico CHARACTER(10), dic CHARACTER(14), banka CHARACTER(25), ucet CHARACTER(25), telefon CHARACTER(25), naz1 CHARACTER(30), naz2 CHARACTER(30), naz3 CHARACTER(30), naz4 CHARACTER(30), naz5 CHARACTER(30), naz6 CHARACTER(30), splatnost numeric(20,10), cen_hlad CHARACTER(2), sleva_proc numeric(20,10), c_data INTEGER, idriadok INTEGER, icdph CHARACTER(16), alkokod CHARACTER(30), ext_id INTEGER, ext_intern CHARACTER(15), platcadph SMALLINT, zmena TIMESTAMP WITHOUT TIME ZONE, edi_kod CHARACTER(15), typ_obj SMALLINT, edi_mankod SMALLINT, platba CHARACTER(5), email CHARACTER(50), popis TEXT) ;
							ALTER TABLE food600.partneri ENABLE TRIGGER ALL;
							SELECT MAX(c_partner) INTO maxid FROM food600.partneri;
							IF maxid IS NULL THEN
								maxid:=0;
							END IF;
							UPDATE food600.maxima SET i_max=maxid+1 WHERE btrim(soubor)='c_partner';
							IF NOT FOUND THEN
								INSERT INTO food600.maxima (soubor, i_max) VALUES ('c_partner',maxid+1);
							END IF;
							SELECT MAX(idriadok) into maxid FROM food600.partneri;
							SELECT nextval('food600.partneri_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.partneri_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.partneri_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='obr_alk' THEN
							ALTER TABLE food600.obr_alk DISABLE TRIGGER ALL;
							TRUNCATE food600.obr_alk RESTART IDENTITY;
							INSERT INTO food600.obr_alk(c_karty, ean, c_partner, datum, c_dokl, autor, c_stredisk, operace, uzaverka, spracovane, zostatok, idriadok, pocet, u_cis, id_kas, dovod, c_data, c_prev, idriadok_master)
								SELECT c_karty, ean, c_partner, datum, c_dokl, autor, c_stredisk, operace, uzaverka, spracovane, zostatok, idriadok, pocet, u_cis, id_kas, dovod, c_data, c_prev, idriadok as idriadok_master FROM dblink('connstrx','SELECT c_karty, ean, c_partner, datum, c_dokl, autor, c_stredisk, operace, uzaverka, spracovane, zostatok, idriadok, pocet, u_cis, id_kas, dovod, c_data, c_prev FROM food600.obr_alk ORDER BY idriadok') 
								as remzmeny(c_karty INTEGER, ean CHARACTER(30), c_partner INTEGER, datum DATE, c_dokl INTEGER, autor CHARACTER(3), c_stredisk INTEGER, operace CHARACTER(2), uzaverka CHARACTER(17), spracovane SMALLINT, zostatok INTEGER, idriadok INTEGER, pocet INTEGER, u_cis CHARACTER(7), id_kas CHARACTER(2), dovod CHARACTER VARYING, c_data INTEGER, c_prev INTEGER) ;
							ALTER TABLE food600.obr_alk ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.obr_alk;
							SELECT nextval('food600.obr_alk_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.obr_alk_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.obr_alk_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='druhy_pl' THEN
							ALTER TABLE food600.druhy_pl DISABLE TRIGGER ALL;
							TRUNCATE food600.druhy_pl RESTART IDENTITY;
							INSERT INTO food600.druhy_pl(nazev_klic, nazev, prg_dotaz, prg_natiz, pl_druh, zaokr, j0, j1, j2, j3, j4, kod_pl, do_recepce, do_limitu, order_en, text, cisfplat, typ_komb, komp_pol, komp_pl, zal_pl, typpl, idriadok, prplmencen, nemen_cenu, ajpozlave, ajpocenovejhladine, platimojazlava, platimojahladina, nfpl, allow_tip, overpay, poradie, pocetkopii, sdph_pl, terminal, odvod, odovzdat, idriadok_master)
								SELECT nazev_klic, nazev, prg_dotaz, prg_natiz, pl_druh, zaokr, j0, j1, j2, j3, j4, kod_pl, do_recepce, do_limitu, order_en, text, cisfplat, typ_komb, komp_pol, komp_pl, zal_pl, typpl, idriadok, prplmencen, nemen_cenu, ajpozlave, ajpocenovejhladine, platimojazlava, platimojahladina, nfpl, allow_tip, overpay, poradie, pocetkopii, sdph_pl, terminal, odvod, odovzdat, idriadok as idriadok_master FROM dblink('connstrx','SELECT nazev_klic, nazev, prg_dotaz, prg_natiz, pl_druh, zaokr, j0, j1, j2, j3, j4, kod_pl, do_recepce, do_limitu, order_en, text, cisfplat, typ_komb, komp_pol, komp_pl, zal_pl, typpl, idriadok, prplmencen, nemen_cenu, ajpozlave, ajpocenovejhladine, platimojazlava, platimojahladina, nfpl, allow_tip, overpay, poradie, pocetkopii, sdph_pl, terminal, odvod, odovzdat FROM food600.druhy_pl ORDER BY idriadok') 
								as remzmeny(nazev_klic CHARACTER(25), nazev CHARACTER(8), prg_dotaz CHARACTER(30), prg_natiz CHARACTER(30), pl_druh INTEGER, zaokr SMALLINT, j0 CHARACTER(30), j1 CHARACTER(30), j2 CHARACTER(30), j3 CHARACTER(30), j4 CHARACTER(30), kod_pl CHARACTER(5), do_recepce SMALLINT, do_limitu SMALLINT, order_en SMALLINT, text SMALLINT, cisfplat NUMERIC(2,0), typ_komb CHARACTER(1), komp_pol CHARACTER(18), komp_pl CHARACTER(8), zal_pl CHARACTER(8), typpl CHARACTER(1), idriadok INTEGER, prplmencen SMALLINT, nemen_cenu SMALLINT, ajpozlave SMALLINT, ajpocenovejhladine SMALLINT, platimojazlava SMALLINT, platimojahladina SMALLINT, nfpl SMALLINT, allow_tip BOOLEAN, overpay SMALLINT, poradie SMALLINT, pocetkopii SMALLINT, sdph_pl NUMERIC(5,2), terminal BOOLEAN, odvod SMALLINT, odovzdat CHARACTER(1)) ;
							ALTER TABLE food600.druhy_pl ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.druhy_pl;
							SELECT nextval('food600.druhy_pl_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.druhy_pl_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.druhy_pl_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='fdct' THEN
							ALTER TABLE food600.fdct DISABLE TRIGGER ALL;
							TRUNCATE food600.fdct RESTART IDENTITY;
							INSERT INTO food600.fdct(c_pole, popis, id_kas, c_data, idriadok, itemizer, idriadok_master)
								SELECT c_pole, popis, id_kas, c_data, idriadok, itemizer, idriadok as idriadok_master FROM dblink('connstrx','SELECT c_pole, popis, id_kas, c_data, idriadok, itemizer FROM food600.fdct ORDER BY idriadok') 
								as remzmeny(c_pole CHARACTER(5), popis CHARACTER(20), id_kas CHARACTER(2), c_data INTEGER, idriadok INTEGER, itemizer CHARACTER(3)) ;
							ALTER TABLE food600.fdct ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.fdct;
							SELECT nextval('food600.fdct_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.fdct_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.fdct_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='fras_set' THEN
							ALTER TABLE food600.fras_set DISABLE TRIGGER ALL;
							TRUNCATE food600.fras_set RESTART IDENTITY;
							INSERT INTO food600.fras_set(rastr, kdy, kdo, c_druh, id, idriadok, c_data, rastr1, rastr2, rastr3, rastr4, rastr5, rastr6, rastr7, rastr8, rastr9, iddruh, idriadok_master)
								SELECT rastr, kdy, kdo, c_druh, id, idriadok, c_data, rastr1, rastr2, rastr3, rastr4, rastr5, rastr6, rastr7, rastr8, rastr9, iddruh, idriadok as idriadok_master FROM dblink('connstrx','SELECT rastr, kdy, kdo, c_druh, id, idriadok, c_data, rastr1, rastr2, rastr3, rastr4, rastr5, rastr6, rastr7, rastr8, rastr9, iddruh FROM food600.fras_set ORDER BY idriadok') 
								as remzmeny(rastr CHARACTER(5), kdy CHARACTER(17), kdo CHARACTER VARYING(3), c_druh INTEGER, id CHARACTER(2), idriadok INTEGER, c_data SMALLINT, rastr1 CHARACTER(5), rastr2 CHARACTER(5), rastr3 CHARACTER(5), rastr4 CHARACTER(5), rastr5 CHARACTER(5), rastr6 CHARACTER(5), rastr7 CHARACTER(5), rastr8 CHARACTER(5), rastr9 CHARACTER(5), iddruh CHARACTER(2)) ;
							ALTER TABLE food600.fras_set ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.fras_set;
							SELECT nextval('food600.fras_set_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.fras_set_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.fras_set_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='h10_set' THEN
							ALTER TABLE food600.h10_set DISABLE TRIGGER ALL;
							TRUNCATE food600.h10_set RESTART IDENTITY;
							INSERT INTO food600.h10_set(c_druh, id_hores, id1, id2, id3, id4, id5, id6, id7, id8, id9, kdo, tmatr, c_data, idriadok, id_kas, kdy, idriadok_master, budova)
								SELECT c_druh, id_hores, id1, id2, id3, id4, id5, id6, id7, id8, id9, kdo, tmatr, c_data, idriadok, id_kas, kdy, idriadok as idriadok_master, budova FROM dblink('connstrx','SELECT c_druh, id_hores, id1, id2, id3, id4, id5, id6, id7, id8, id9, kdo, tmatr, c_data, idriadok, id_kas, kdy, budova FROM food600.h10_set ORDER BY idriadok') 
								as remzmeny(c_druh INTEGER, id_hores INTEGER, id1 INTEGER, id2 INTEGER, id3 INTEGER, id4 INTEGER, id5 INTEGER, id6 INTEGER, id7 INTEGER, id8 INTEGER, id9 INTEGER, kdo CHARACTER(3), tmatr CHARACTER(1), c_data INTEGER, idriadok INTEGER, id_kas CHARACTER(2), kdy CHARACTER(17), budova CHARACTER(30)) ;
							ALTER TABLE food600.h10_set ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.h10_set;
							SELECT nextval('food600.h10_set_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.h10_set_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.h10_set_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='h10crc_set' THEN
							ALTER TABLE food600.h10crc_set DISABLE TRIGGER ALL;
							TRUNCATE food600.h10crc_set RESTART IDENTITY;
							INSERT INTO food600.h10crc_set(id_hores, hot_kod_id, kodcc_id, po_uctoch, druh_pl, c_data, idriadok, idriadok_master)
								SELECT id_hores, hot_kod_id, kodcc_id, po_uctoch, druh_pl, c_data, idriadok, idriadok as idriadok_master FROM dblink('connstrx','SELECT id_hores, hot_kod_id, kodcc_id, po_uctoch, druh_pl, c_data, idriadok FROM food600.h10crc_set ORDER BY idriadok') 
								as remzmeny(id_hores INTEGER, hot_kod_id INTEGER, kodcc_id INTEGER, po_uctoch SMALLINT, druh_pl CHARACTER(8), c_data INTEGER, idriadok INTEGER) ;
							ALTER TABLE food600.h10crc_set ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.h10crc_set;
							SELECT nextval('food600.h10crc_set_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.h10crc_set_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.h10crc_set_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='hores_d' THEN
							ALTER TABLE food600.hores_d DISABLE TRIGGER ALL;
							TRUNCATE food600.hores_d RESTART IDENTITY;
							INSERT INTO food600.hores_d(hor_pref, hor_path, hor_hotel, hor_cdx, idriadok, hor_ip, hor_port, hor_meno, hor_heslo, hor_kasa, idriadok_master, api_meno, api_heslo)
								SELECT hor_pref, hor_path, hor_hotel, hor_cdx, idriadok, hor_ip, hor_port, hor_meno, hor_heslo, hor_kasa, idriadok as idriadok_master, api_meno, api_heslo FROM dblink('connstrx','SELECT hor_pref, hor_path, hor_hotel, hor_cdx, idriadok, hor_ip, hor_port, hor_meno, hor_heslo, hor_kasa, api_meno, api_heslo FROM food600.hores_d ORDER BY idriadok') 
								as remzmeny(hor_pref CHARACTER(1), hor_path CHARACTER(200), hor_hotel CHARACTER(25), hor_cdx SMALLINT, idriadok INTEGER, hor_ip CHARACTER(15), hor_port INTEGER, hor_meno CHARACTER(30), hor_heslo CHARACTER(30), hor_kasa CHARACTER(2), api_meno CHARACTER(30), api_heslo CHARACTER(30)) ;
							ALTER TABLE food600.hores_d ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.hores_d;
							SELECT nextval('food600.hores_d_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.hores_d_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.hores_d_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='kas_utxt' THEN
							ALTER TABLE food600.kas_utxt DISABLE TRIGGER ALL;
							TRUNCATE food600.kas_utxt RESTART IDENTITY;
							INSERT INTO food600.kas_utxt(id_kas, userhead1, userhead2, userhead3, userhead4, userhead5, userhead6, userhead7, userhead8, usertail1, usertail2, usertail3, usertail4, usertail5, usertail6, idriadok, idriadok_master)
								SELECT id_kas, userhead1, userhead2, userhead3, userhead4, userhead5, userhead6, userhead7, userhead8, usertail1, usertail2, usertail3, usertail4, usertail5, usertail6, idriadok, idriadok as idriadok_master FROM dblink('connstrx','SELECT id_kas, userhead1, userhead2, userhead3, userhead4, userhead5, userhead6, userhead7, userhead8, usertail1, usertail2, usertail3, usertail4, usertail5, usertail6, idriadok FROM food600.kas_utxt ORDER BY idriadok') 
								as remzmeny(id_kas CHARACTER(2), userhead1 CHARACTER(40), userhead2 CHARACTER(40), userhead3 CHARACTER(40), userhead4 CHARACTER(40), userhead5 CHARACTER(40), userhead6 CHARACTER(40), userhead7 CHARACTER(40), userhead8 CHARACTER(40), usertail1 CHARACTER(40), usertail2 CHARACTER(40), usertail3 CHARACTER(40), usertail4 CHARACTER(40), usertail5 CHARACTER(40), usertail6 CHARACTER(40), idriadok INTEGER) ;
							ALTER TABLE food600.kas_utxt ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.kas_utxt;
							SELECT nextval('food600.kas_utxt_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.kas_utxt_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.kas_utxt_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='kasa_set' THEN
							ALTER TABLE food600.kasa_set DISABLE TRIGGER ALL;
							TRUNCATE food600.kasa_set RESTART IDENTITY;
							INSERT INTO food600.kasa_set(idriadok, poc_stolu, uzav_prn, uzav_no, max_ucis, last_dokla, uz_cislo, uz_date, uz_time, uz_suma, hor_path, sme_path, sme_odpoc, userplat1, userplat2, pokl_hrmc, set_dat, set_cas, pokl_horec, ducis, pokl_front, pokl_gubi, last_vklvy, master_id, id_fmenu, idriadok_master)
								SELECT idriadok, poc_stolu, uzav_prn, uzav_no, max_ucis, last_dokla, uz_cislo, uz_date, uz_time, uz_suma, hor_path, sme_path, sme_odpoc, userplat1, userplat2, pokl_hrmc, set_dat, set_cas, pokl_horec, ducis, pokl_front, pokl_gubi, last_vklvy, master_id, id_fmenu, idriadok as idriadok_master FROM dblink('connstrx','SELECT idriadok, poc_stolu, uzav_prn, uzav_no, max_ucis, last_dokla, uz_cislo, uz_date, uz_time, uz_suma, hor_path, sme_path, sme_odpoc, userplat1, userplat2, pokl_hrmc, set_dat, set_cas, pokl_horec, ducis, pokl_front, pokl_gubi, last_vklvy, master_id, id_fmenu FROM food600.kasa_set ORDER BY idriadok') 
								as remzmeny(idriadok INTEGER, poc_stolu INTEGER, uzav_prn CHARACTER(4), uzav_no CHARACTER(2), max_ucis NUMERIC(5,0), last_dokla NUMERIC(5,0), uz_cislo INTEGER, uz_date DATE, uz_time CHARACTER(5), uz_suma NUMERIC(9,2), hor_path CHARACTER(40), sme_path CHARACTER(40), sme_odpoc CHARACTER(6), userplat1 CHARACTER(30), userplat2 CHARACTER(30), pokl_hrmc CHARACTER(3), set_dat DATE, set_cas CHARACTER(5), pokl_horec CHARACTER(5), ducis INTEGER, pokl_front NUMERIC(11,0), pokl_gubi NUMERIC(5,0), last_vklvy NUMERIC(5,0), master_id CHARACTER(2), id_fmenu INTEGER) ;
							ALTER TABLE food600.kasa_set ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.kasa_set;
							SELECT nextval('food600.kasa_set_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.kasa_set_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.kasa_set_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='kasa_ucp' THEN
							ALTER TABLE food600.kasa_ucp DISABLE TRIGGER ALL;
							TRUNCATE food600.kasa_ucp RESTART IDENTITY;
							INSERT INTO food600.kasa_ucp(idriadok, master_id, id, ucet_prn, ucet_no, poradie, idriadok_master)
								SELECT idriadok, master_id, id, ucet_prn, ucet_no, poradie, idriadok as idriadok_master FROM dblink('connstrx','SELECT idriadok, master_id, id, ucet_prn, ucet_no, poradie FROM food600.kasa_ucp ORDER BY idriadok') 
								as remzmeny(idriadok INTEGER, master_id CHARACTER(2), id CHARACTER(2), ucet_prn CHARACTER(4), ucet_no CHARACTER(2), poradie SMALLINT) ;
							ALTER TABLE food600.kasa_ucp ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.kasa_ucp;
							SELECT nextval('food600.kasa_ucp_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.kasa_ucp_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.kasa_ucp_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='kceny' THEN
							ALTER TABLE food600.kceny DISABLE TRIGGER ALL;
							TRUNCATE food600.kceny RESTART IDENTITY;
							INSERT INTO food600.kceny(c_data, c_karty, idriadok, idriadok_master, cenaa0, cenaa1, cenaa2, cenaa3, cenaa4, cenaa5, cenaa6, cenaa7, cenaa8, cenaa9, cenab0, cenab1, cenab2, cenab3, cenab4, cenab5, cenab6, cenab7, cenab8, cenab9, cenac0, cenac1, cenac2, cenac3, cenac4, cenac5, cenac6, cenac7, cenac8, cenac9, cenad0, cenad1, cenad2, cenad3, cenad4, cenad5, cenad6, cenad7, cenad8, cenad9, cenae0, cenae1, cenae2, cenae3, cenae4, cenae5, cenae6, cenae7, cenae8, cenae9, cenaf0, cenaf1, cenaf2, cenaf3, cenaf4, cenaf5, cenaf6, cenaf7, cenaf8, cenaf9, cenag0, cenag1, cenag2, cenag3, cenag4, cenag5, cenag6, cenag7, cenag8, cenag9, cenah0, cenah1, cenah2, cenah3, cenah4, cenah5, cenah6, cenah7, cenah8, cenah9, cenai0, cenai1, cenai2, cenai3, cenai4, cenai5, cenai6, cenai7, cenai8, cenai9, cenaj0, cenaj1, cenaj2, cenaj3, cenaj4, cenaj5, cenaj6, cenaj7, cenaj8, cenaj9, cenak0, cenak1, cenak2, cenak3, cenak4, cenak5, cenak6, cenak7, cenak8, cenak9, cenal0, cenal1, cenal2, cenal3, cenal4, cenal5, cenal6, cenal7, cenal8, cenal9)
								SELECT c_data, c_karty, idriadok, idriadok as id_riadok_master, cenaa0, cenaa1, cenaa2, cenaa3, cenaa4, cenaa5, cenaa6, cenaa7, cenaa8, cenaa9, cenab0, cenab1, cenab2, cenab3, cenab4, cenab5, cenab6, cenab7, cenab8, cenab9, cenac0, cenac1, cenac2, cenac3, cenac4, cenac5, cenac6, cenac7, cenac8, cenac9, cenad0, cenad1, cenad2, cenad3, cenad4, cenad5, cenad6, cenad7, cenad8, cenad9, cenae0, cenae1, cenae2, cenae3, cenae4, cenae5, cenae6, cenae7, cenae8, cenae9, cenaf0, cenaf1, cenaf2, cenaf3, cenaf4, cenaf5, cenaf6, cenaf7, cenaf8, cenaf9, cenag0, cenag1, cenag2, cenag3, cenag4, cenag5, cenag6, cenag7, cenag8, cenag9, cenah0, cenah1, cenah2, cenah3, cenah4, cenah5, cenah6, cenah7, cenah8, cenah9, cenai0, cenai1, cenai2, cenai3, cenai4, cenai5, cenai6, cenai7, cenai8, cenai9, cenaj0, cenaj1, cenaj2, cenaj3, cenaj4, cenaj5, cenaj6, cenaj7, cenaj8, cenaj9, cenak0, cenak1, cenak2, cenak3, cenak4, cenak5, cenak6, cenak7, cenak8, cenak9, cenal0, cenal1, cenal2, cenal3, cenal4, cenal5, cenal6, cenal7, cenal8, cenal9 FROM dblink('connstrx','SELECT c_data, c_karty, idriadok, cenaa0, cenaa1, cenaa2, cenaa3, cenaa4, cenaa5, cenaa6, cenaa7, cenaa8, cenaa9, cenab0, cenab1, cenab2, cenab3, cenab4, cenab5, cenab6, cenab7, cenab8, cenab9, cenac0, cenac1, cenac2, cenac3, cenac4, cenac5, cenac6, cenac7, cenac8, cenac9, cenad0, cenad1, cenad2, cenad3, cenad4, cenad5, cenad6, cenad7, cenad8, cenad9, cenae0, cenae1, cenae2, cenae3, cenae4, cenae5, cenae6, cenae7, cenae8, cenae9, cenaf0, cenaf1, cenaf2, cenaf3, cenaf4, cenaf5, cenaf6, cenaf7, cenaf8, cenaf9, cenag0, cenag1, cenag2, cenag3, cenag4, cenag5, cenag6, cenag7, cenag8, cenag9, cenah0, cenah1, cenah2, cenah3, cenah4, cenah5, cenah6, cenah7, cenah8, cenah9, cenai0, cenai1, cenai2, cenai3, cenai4, cenai5, cenai6, cenai7, cenai8, cenai9, cenaj0, cenaj1, cenaj2, cenaj3, cenaj4, cenaj5, cenaj6, cenaj7, cenaj8, cenaj9, cenak0, cenak1, cenak2, cenak3, cenak4, cenak5, cenak6, cenak7, cenak8, cenak9, cenal0, cenal1, cenal2, cenal3, cenal4, cenal5, cenal6, cenal7, cenal8, cenal9 FROM food600.kceny ORDER BY idriadok') 
								as remzmeny(c_data INTEGER, c_karty INTEGER, idriadok INTEGER, cenaa0 NUMERIC, cenaa1 NUMERIC, cenaa2 NUMERIC, cenaa3 NUMERIC, cenaa4 NUMERIC, cenaa5 NUMERIC, cenaa6 NUMERIC, cenaa7 NUMERIC, cenaa8 NUMERIC, cenaa9 NUMERIC, cenab0 NUMERIC, cenab1 NUMERIC, cenab2 NUMERIC, cenab3 NUMERIC, cenab4 NUMERIC, cenab5 NUMERIC, cenab6 NUMERIC, cenab7 NUMERIC, cenab8 NUMERIC, cenab9 NUMERIC, cenac0 NUMERIC, cenac1 NUMERIC, cenac2 NUMERIC, cenac3 NUMERIC, cenac4 NUMERIC, cenac5 NUMERIC, cenac6 NUMERIC, cenac7 NUMERIC, cenac8 NUMERIC, cenac9 NUMERIC, cenad0 NUMERIC, cenad1 NUMERIC, cenad2 NUMERIC, cenad3 NUMERIC, cenad4 NUMERIC, cenad5 NUMERIC, cenad6 NUMERIC, cenad7 NUMERIC, cenad8 NUMERIC, cenad9 NUMERIC, cenae0 NUMERIC, cenae1 NUMERIC, cenae2 NUMERIC, cenae3 NUMERIC, cenae4 NUMERIC, cenae5 NUMERIC, cenae6 NUMERIC, cenae7 NUMERIC, cenae8 NUMERIC, cenae9 NUMERIC, cenaf0 NUMERIC, cenaf1 NUMERIC, cenaf2 NUMERIC, cenaf3 NUMERIC, cenaf4 NUMERIC, cenaf5 NUMERIC, cenaf6 NUMERIC, cenaf7 NUMERIC, cenaf8 NUMERIC, cenaf9 NUMERIC, cenag0 NUMERIC, cenag1 NUMERIC, cenag2 NUMERIC, cenag3 NUMERIC, cenag4 NUMERIC, cenag5 NUMERIC, cenag6 NUMERIC, cenag7 NUMERIC, cenag8 NUMERIC, cenag9 NUMERIC, cenah0 NUMERIC, cenah1 NUMERIC, cenah2 NUMERIC, cenah3 NUMERIC, cenah4 NUMERIC, cenah5 NUMERIC, cenah6 NUMERIC, cenah7 NUMERIC, cenah8 NUMERIC, cenah9 NUMERIC, cenai0 NUMERIC, cenai1 NUMERIC, cenai2 NUMERIC, cenai3 NUMERIC, cenai4 NUMERIC, cenai5 NUMERIC, cenai6 NUMERIC, cenai7 NUMERIC, cenai8 NUMERIC, cenai9 NUMERIC, cenaj0 NUMERIC, cenaj1 NUMERIC, cenaj2 NUMERIC, cenaj3 NUMERIC, cenaj4 NUMERIC, cenaj5 NUMERIC, cenaj6 NUMERIC, cenaj7 NUMERIC, cenaj8 NUMERIC, cenaj9 NUMERIC, cenak0 NUMERIC, cenak1 NUMERIC, cenak2 NUMERIC, cenak3 NUMERIC, cenak4 NUMERIC, cenak5 NUMERIC, cenak6 NUMERIC, cenak7 NUMERIC, cenak8 NUMERIC, cenak9 NUMERIC, cenal0 NUMERIC, cenal1 NUMERIC, cenal2 NUMERIC, cenal3 NUMERIC, cenal4 NUMERIC, cenal5 NUMERIC, cenal6 NUMERIC, cenal7 NUMERIC, cenal8 NUMERIC, cenal9 NUMERIC) ;
							ALTER TABLE food600.kceny ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.kceny;
							SELECT nextval('food600.kceny_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.kceny_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.kceny_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='krest' THEN
							ALTER TABLE food600.krest DISABLE TRIGGER ALL;
							TRUNCATE food600.krest RESTART IDENTITY;
							INSERT INTO food600.krest(idriadok, c_karty, obrazok, c_data, alergeny, kal_zad, kalorie, cas1, cas2, cas3, poznamka, teplota, idriadok_master)
								SELECT idriadok, c_karty, obrazok, c_data, alergeny, kal_zad, kalorie, cas1, cas2, cas3, poznamka, teplota, idriadok as idriadok_master FROM dblink('connstrx','SELECT idriadok, c_karty, obrazok, c_data, alergeny, kal_zad, kalorie, cas1, cas2, cas3, poznamka, teplota FROM food600.krest ORDER BY idriadok') 
								as remzmeny(idriadok INTEGER, c_karty INTEGER, obrazok BYTEA, c_data SMALLINT, alergeny INTEGER, kal_zad numeric(20,10), kalorie numeric(20,10), cas1 INTEGER, cas2 INTEGER, cas3 INTEGER, poznamka TEXT, teplota INTEGER) ;
							ALTER TABLE food600.krest ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.krest;
							SELECT nextval('food600.krest_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.krest_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.krest_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='ktexty' THEN
							ALTER TABLE food600.ktexty DISABLE TRIGGER ALL;
							TRUNCATE food600.ktexty RESTART IDENTITY;
							INSERT INTO food600.ktexty(idriadok, c_karty, nazev1, nazev2, nazev3, nazev4, nazev5, naz1, naz2, naz3, naz4, naz5, meno1, meno2, meno3, meno4, meno5, vyr_postup, c_data, idriadok_master)
								SELECT idriadok, c_karty, nazev1, nazev2, nazev3, nazev4, nazev5, naz1, naz2, naz3, naz4, naz5, meno1, meno2, meno3, meno4, meno5, vyr_postup, c_data, idriadok as idriadok_master FROM dblink('connstrx','SELECT idriadok, c_karty, nazev1, nazev2, nazev3, nazev4, nazev5, naz1, naz2, naz3, naz4, naz5, meno1, meno2, meno3, meno4, meno5, vyr_postup, c_data FROM food600.ktexty ORDER BY idriadok') 
								as remzmeny(idriadok INTEGER, c_karty INTEGER, nazev1 CHARACTER VARYING(27), nazev2 CHARACTER VARYING(27), nazev3 CHARACTER VARYING(27), nazev4 CHARACTER VARYING(27), nazev5 CHARACTER VARYING(27), naz1 CHARACTER VARYING(30), naz2 CHARACTER VARYING(30), naz3 CHARACTER VARYING(30), naz4 CHARACTER VARYING(30), naz5 CHARACTER VARYING(30), meno1 CHARACTER VARYING(60), meno2 CHARACTER VARYING(60), meno3 CHARACTER VARYING(60), meno4 CHARACTER VARYING(60), meno5 CHARACTER VARYING(60), vyr_postup TEXT, c_data INTEGER) ;
							ALTER TABLE food600.ktexty ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.ktexty;
							SELECT nextval('food600.ktexty_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.ktexty_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.ktexty_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='miestnosti' THEN
							ALTER TABLE food600.miestnosti DISABLE TRIGGER ALL;
							TRUNCATE food600.miestnosti RESTART IDENTITY;
							INSERT INTO food600.miestnosti(id_miest, pozadie, miest, id_miest_master)
								SELECT id_miest, pozadie, miest, id_miest as id_miest_master FROM dblink('connstrx','SELECT id_miest, pozadie, miest FROM food600.miestnosti ORDER BY id_miest') 
								as remzmeny(id_miest INTEGER, pozadie BYTEA, miest CHARACTER(30)) ;
							ALTER TABLE food600.miestnosti ENABLE TRIGGER ALL;
							SELECT MAX(id_miest) into maxid FROM food600.miestnosti;
							SELECT nextval('food600.miestnosti_id_miest_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.miestnosti_id_miest_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.miestnosti_id_miest_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='miestnostikukase' THEN
							ALTER TABLE food600.miestnostikukase DISABLE TRIGGER ALL;
							TRUNCATE food600.miestnostikukase RESTART IDENTITY;
							INSERT INTO food600.miestnostikukase(id_kas, id_miest, idriadok, poradie, idriadok_master)
								SELECT id_kas, id_miest, idriadok, poradie, idriadok as idriadok_master FROM dblink('connstrx','SELECT id_kas, id_miest, idriadok, poradie FROM food600.miestnostikukase ORDER BY idriadok') 
								as remzmeny(id_kas CHARACTER(2), id_miest INTEGER, idriadok INTEGER, poradie INTEGER) ;
							ALTER TABLE food600.miestnostikukase ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.miestnostikukase;
							SELECT nextval('food600.miestnostikukase_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.miestnostikukase_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.miestnostikukase_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='prn_def' THEN
							ALTER TABLE food600.prn_def DISABLE TRIGGER ALL;
							TRUNCATE food600.prn_def RESTART IDENTITY;
							INSERT INTO food600.prn_def(prn_no, prn_no_alt, prn_name, p_name, comment, cmd_on, cmd_off, cmd_cs, p_reset, p_crlf, p_ff, p_6lpi, p_8lpi, p_10cpi, p_12cpi, p_16cpi, p_boldon, p_boldoff, p_ulineon, p_ulineoff, p_wideon, p_wideoff, p_italon, p_italoff, p_draft, p_nlq, p_fullcut, p_partcut, p_ucetfeed, p_width, p_horiz, typ_diakr, cmd32_on, ord_link, ord_adr, p_kopii, is_netprn, p_header, p_paragon, p_paragoff, typ_fiskal, idriadok, failed_bills, unrecoverable_bills, idriadok_master)
								SELECT prn_no, prn_no_alt, prn_name, p_name, comment, cmd_on, cmd_off, cmd_cs, p_reset, p_crlf, p_ff, p_6lpi, p_8lpi, p_10cpi, p_12cpi, p_16cpi, p_boldon, p_boldoff, p_ulineon, p_ulineoff, p_wideon, p_wideoff, p_italon, p_italoff, p_draft, p_nlq, p_fullcut, p_partcut, p_ucetfeed, p_width, p_horiz, typ_diakr, cmd32_on, ord_link, ord_adr, p_kopii, is_netprn, p_header, p_paragon, p_paragoff, typ_fiskal, idriadok, failed_bills, unrecoverable_bills, idriadok as idriadok_master FROM dblink('connstrx','SELECT prn_no, prn_no_alt, prn_name, p_name, comment, cmd_on, cmd_off, cmd_cs, p_reset, p_crlf, p_ff, p_6lpi, p_8lpi, p_10cpi, p_12cpi, p_16cpi, p_boldon, p_boldoff, p_ulineon, p_ulineoff, p_wideon, p_wideoff, p_italon, p_italoff, p_draft, p_nlq, p_fullcut, p_partcut, p_ucetfeed, p_width, p_horiz, typ_diakr, cmd32_on, ord_link, ord_adr, p_kopii, is_netprn, p_header, p_paragon, p_paragoff, typ_fiskal, idriadok, failed_bills, unrecoverable_bills FROM food600.prn_def ORDER BY idriadok') 
								as remzmeny(prn_no CHARACTER(2), prn_no_alt CHARACTER(2), prn_name CHARACTER(20), p_name CHARACTER(20), comment CHARACTER(66), cmd_on CHARACTER(80), cmd_off CHARACTER(80), cmd_cs CHARACTER(80), p_reset CHARACTER(50), p_crlf CHARACTER(50), p_ff CHARACTER(50), p_6lpi CHARACTER(50), p_8lpi CHARACTER(50), p_10cpi CHARACTER(50), p_12cpi CHARACTER(50), p_16cpi CHARACTER(50), p_boldon CHARACTER(50), p_boldoff CHARACTER(50), p_ulineon CHARACTER(50), p_ulineoff CHARACTER(50), p_wideon CHARACTER(50), p_wideoff CHARACTER(50), p_italon CHARACTER(50), p_italoff CHARACTER(50), p_draft CHARACTER(50), p_nlq CHARACTER(50), p_fullcut CHARACTER(60), p_partcut CHARACTER(50), p_ucetfeed NUMERIC, p_width CHARACTER(2), p_horiz CHARACTER(50), typ_diakr CHARACTER(10), cmd32_on CHARACTER(80), ord_link CHARACTER(2), ord_adr CHARACTER(5), p_kopii NUMERIC, is_netprn SMALLINT, p_header SMALLINT, p_paragon CHARACTER(50), p_paragoff CHARACTER(50), typ_fiskal CHARACTER(10), idriadok INTEGER, failed_bills INTEGER, unrecoverable_bills INTEGER) ;
							ALTER TABLE food600.prn_def ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.prn_def;
							SELECT nextval('food600.prn_def_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.prn_def_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.prn_def_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='spravykukase' THEN
							ALTER TABLE food600.spravykukase DISABLE TRIGGER ALL;
							TRUNCATE food600.spravykukase RESTART IDENTITY;
							INSERT INTO food600.spravykukase(id_kas, id_sprava, idriadok, poradie, idriadok_master)
								SELECT id_kas, id_sprava, idriadok, poradie, idriadok as idriadok_master FROM dblink('connstrx','SELECT id_kas, id_sprava, idriadok, poradie FROM food600.spravykukase ORDER BY idriadok') 
								as remzmeny(id_kas CHARACTER(2), id_sprava INTEGER, idriadok INTEGER, poradie INTEGER) ;
							ALTER TABLE food600.spravykukase ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.spravykukase;
							SELECT nextval('food600.spravykukase_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.spravykukase_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.spravykukase_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='spravy' THEN
							ALTER TABLE food600.spravy DISABLE TRIGGER ALL;
							TRUNCATE food600.spravy RESTART IDENTITY;
							INSERT INTO food600.spravy(id_sprava, sprava, c_data, id_sprava_master)
								SELECT id_sprava, sprava, c_data, id_sprava as id_sprava_master FROM dblink('connstrx','SELECT id_sprava, sprava, c_data FROM food600.spravy ORDER BY id_sprava') 
								as remzmeny(id_sprava INTEGER, sprava CHARACTER VARYING(40), c_data INTEGER) ;
							ALTER TABLE food600.spravy ENABLE TRIGGER ALL;
							SELECT MAX(id_sprava) into maxid FROM food600.spravy;
							SELECT nextval('food600.spravy_id_sprava_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.spravy_id_sprava_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.spravy_id_sprava_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='spravyskupiny' THEN
							ALTER TABLE food600.spravyskupiny DISABLE TRIGGER ALL;
							TRUNCATE food600.spravyskupiny RESTART IDENTITY;
							INSERT INTO food600.spravyskupiny(id_skup, skupina, c_data, zmena, id_skup_master)
								SELECT id_skup, skupina, c_data, zmena, id_skup as id_skup_master FROM dblink('connstrx','SELECT id_skup, skupina, c_data, zmena FROM food600.spravyskupiny ORDER BY id_skup') 
								as remzmeny(id_skup INTEGER, skupina CHARACTER VARYING(40), c_data INTEGER, zmena TIMESTAMP WITHOUT TIME ZONE) ;
							ALTER TABLE food600.spravyskupiny ENABLE TRIGGER ALL;
							SELECT MAX(id_skup) into maxid FROM food600.spravyskupiny;
							SELECT nextval('food600.spravyskupiny_id_skup_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.spravyskupiny_id_skup_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.spravyskupiny_id_skup_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='spravyvskupine' THEN
							ALTER TABLE food600.spravyvskupine DISABLE TRIGGER ALL;
							TRUNCATE food600.spravyvskupine RESTART IDENTITY;
							INSERT INTO food600.spravyvskupine(id_skup, id_sprava, idriadok, poradie, idriadok_master)
								SELECT id_skup, id_sprava, idriadok, poradie, idriadok as idriadok_master FROM dblink('connstrx','SELECT id_skup, id_sprava, idriadok, poradie FROM food600.spravyvskupine ORDER BY idriadok') 
								as remzmeny(id_skup INTEGER, id_sprava INTEGER, idriadok INTEGER, poradie INTEGER) ;
							ALTER TABLE food600.spravyvskupine ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.spravyvskupine;
							SELECT nextval('food600.spravyvskupine_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.spravyvskupine_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.spravyvskupine_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='uvery' THEN
							ALTER TABLE food600.uvery DISABLE TRIGGER ALL;
							TRUNCATE food600.uvery RESTART IDENTITY;
							INSERT INTO food600.uvery(hjmeno, adresa1, adresa2, adresa3, akce, schvalil, txt, jmeno, ico, icdph, dic, idriadok, idriadok_master)
								SELECT hjmeno, adresa1, adresa2, adresa3, akce, schvalil, txt, jmeno, ico, icdph, dic, idriadok, idriadok as idriadok_master FROM dblink('connstrx','SELECT hjmeno, adresa1, adresa2, adresa3, akce, schvalil, txt, jmeno, ico, icdph, dic, idriadok FROM food600.uvery ORDER BY idriadok') 
								as remzmeny(hjmeno CHARACTER(35), adresa1 CHARACTER(35), adresa2 CHARACTER(35), adresa3 CHARACTER(35), akce CHARACTER(35), schvalil CHARACTER(35), txt CHARACTER(35), jmeno CHARACTER(35), ico CHARACTER(15), icdph CHARACTER(20), dic CHARACTER(15), idriadok INTEGER) ;
							ALTER TABLE food600.uvery ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.uvery;
							SELECT nextval('food600.uvery_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.uvery_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.uvery_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='vypocty' THEN
							ALTER TABLE food600.vypocty DISABLE TRIGGER ALL;
							TRUNCATE food600.vypocty RESTART IDENTITY;
							INSERT INTO food600.vypocty(c_data, c_druh, druh, spart_kas, typ_kalk, dan01, vypocet01, vypocet02, vypocet03, vypocet04, vypocet05, vypocet06, vypocet07, vypocet08, vypocet09, vypocet10, vypocet11, vypocet12, vypocet13, vypocet14, vypocet15, vypocet16, vypocet17, vypocet18, vypocet19, vypocet20, vypocet21, vypocet22, vypocet23, vypocet24, vypocet25, vypocet26, vypocet27, vypocet28, vypocet29, vypocet30, vypocet31, vypocet32, vypocet33, vypocet34, vypocet35, vypocet36, vypocet37, vypocet38, vypocet39, vypocet40, vypocet41, vypocet42, vypocet43, vypocet44, vypocet45, vypocet46, vypocet47, vypocet48, vypocet49, vypocet50, vypocet51, vypocet52, vypocet53, vypocet54, vypocet55, vypocet56, vypocet57, vypocet58, vypocet59, vypocet60, vypocet61, vypocet62, vypocet63, vypocet64, vypocet65, vypocet66, vypocet67, vypocet68, vypocet69, vypocet70, vypocet71, vypocet72, vypocet73, vypocet74, vypocet75, vypocet76, vypocet77, vypocet78, vypocet79, vypocet80, vypocet81, vypocet82, vypocet83, vypocet84, vypocet85, vypocet86, vypocet87, vypocet88, vypocet89, vypocet90, vypocet91, vypocet92, vypocet93, vypocet94, vypocet95, vypocet96, vypocet97, vypocet98, vypocet99, idriadok, idriadok_master)
								SELECT c_data, c_druh, druh, spart_kas, typ_kalk, dan01, vypocet01, vypocet02, vypocet03, vypocet04, vypocet05, vypocet06, vypocet07, vypocet08, vypocet09, vypocet10, vypocet11, vypocet12, vypocet13, vypocet14, vypocet15, vypocet16, vypocet17, vypocet18, vypocet19, vypocet20, vypocet21, vypocet22, vypocet23, vypocet24, vypocet25, vypocet26, vypocet27, vypocet28, vypocet29, vypocet30, vypocet31, vypocet32, vypocet33, vypocet34, vypocet35, vypocet36, vypocet37, vypocet38, vypocet39, vypocet40, vypocet41, vypocet42, vypocet43, vypocet44, vypocet45, vypocet46, vypocet47, vypocet48, vypocet49, vypocet50, vypocet51, vypocet52, vypocet53, vypocet54, vypocet55, vypocet56, vypocet57, vypocet58, vypocet59, vypocet60, vypocet61, vypocet62, vypocet63, vypocet64, vypocet65, vypocet66, vypocet67, vypocet68, vypocet69, vypocet70, vypocet71, vypocet72, vypocet73, vypocet74, vypocet75, vypocet76, vypocet77, vypocet78, vypocet79, vypocet80, vypocet81, vypocet82, vypocet83, vypocet84, vypocet85, vypocet86, vypocet87, vypocet88, vypocet89, vypocet90, vypocet91, vypocet92, vypocet93, vypocet94, vypocet95, vypocet96, vypocet97, vypocet98, vypocet99, idriadok, idriadok as idriadok_master FROM dblink('connstrx','SELECT c_data, c_druh, druh, spart_kas, typ_kalk, dan01, vypocet01, vypocet02, vypocet03, vypocet04, vypocet05, vypocet06, vypocet07, vypocet08, vypocet09, vypocet10, vypocet11, vypocet12, vypocet13, vypocet14, vypocet15, vypocet16, vypocet17, vypocet18, vypocet19, vypocet20, vypocet21, vypocet22, vypocet23, vypocet24, vypocet25, vypocet26, vypocet27, vypocet28, vypocet29, vypocet30, vypocet31, vypocet32, vypocet33, vypocet34, vypocet35, vypocet36, vypocet37, vypocet38, vypocet39, vypocet40, vypocet41, vypocet42, vypocet43, vypocet44, vypocet45, vypocet46, vypocet47, vypocet48, vypocet49, vypocet50, vypocet51, vypocet52, vypocet53, vypocet54, vypocet55, vypocet56, vypocet57, vypocet58, vypocet59, vypocet60, vypocet61, vypocet62, vypocet63, vypocet64, vypocet65, vypocet66, vypocet67, vypocet68, vypocet69, vypocet70, vypocet71, vypocet72, vypocet73, vypocet74, vypocet75, vypocet76, vypocet77, vypocet78, vypocet79, vypocet80, vypocet81, vypocet82, vypocet83, vypocet84, vypocet85, vypocet86, vypocet87, vypocet88, vypocet89, vypocet90, vypocet91, vypocet92, vypocet93, vypocet94, vypocet95, vypocet96, vypocet97, vypocet98, vypocet99, idriadok FROM food600.vypocty ORDER BY c_druh') 
								 as remzmeny(c_data SMALLINT, c_druh INTEGER, druh CHARACTER(10), spart_kas CHARACTER(3), typ_kalk CHARACTER(1), dan01 NUMERIC(5,3), vypocet01 CHARACTER VARYING(250), vypocet02 CHARACTER VARYING(250), vypocet03 CHARACTER VARYING(250), vypocet04 CHARACTER VARYING(250), vypocet05 CHARACTER VARYING(250), vypocet06 CHARACTER VARYING(250), vypocet07 CHARACTER VARYING(250), vypocet08 CHARACTER VARYING(250), vypocet09 CHARACTER VARYING(250), vypocet10 CHARACTER VARYING(250), vypocet11 CHARACTER VARYING(250), vypocet12 CHARACTER VARYING(250), vypocet13 CHARACTER VARYING(250), vypocet14 CHARACTER VARYING(250), vypocet15 CHARACTER VARYING(250), vypocet16 CHARACTER VARYING(250), vypocet17 CHARACTER VARYING(250), vypocet18 CHARACTER VARYING(250), vypocet19 CHARACTER VARYING(250), vypocet20 CHARACTER VARYING(250), vypocet21 CHARACTER VARYING(250), vypocet22 CHARACTER VARYING(250), vypocet23 CHARACTER VARYING(250), vypocet24 CHARACTER VARYING(250), vypocet25 CHARACTER VARYING(250), vypocet26 CHARACTER VARYING(250), vypocet27 CHARACTER VARYING(250), vypocet28 CHARACTER VARYING(250), vypocet29 CHARACTER VARYING(250), vypocet30 CHARACTER VARYING(250), vypocet31 CHARACTER VARYING(250), vypocet32 CHARACTER VARYING(250), vypocet33 CHARACTER VARYING(250), vypocet34 CHARACTER VARYING(250), vypocet35 CHARACTER VARYING(250), vypocet36 CHARACTER VARYING(250), vypocet37 CHARACTER VARYING(250), vypocet38 CHARACTER VARYING(250), vypocet39 CHARACTER VARYING(250), vypocet40 CHARACTER VARYING(250), vypocet41 CHARACTER VARYING(250), vypocet42 CHARACTER VARYING(250), vypocet43 CHARACTER VARYING(250), vypocet44 CHARACTER VARYING(250), vypocet45 CHARACTER VARYING(250), vypocet46 CHARACTER VARYING(250), vypocet47 CHARACTER VARYING(250), vypocet48 CHARACTER VARYING(250), vypocet49 CHARACTER VARYING(250), vypocet50 CHARACTER VARYING(250), vypocet51 CHARACTER VARYING(250), vypocet52 CHARACTER VARYING(250), vypocet53 CHARACTER VARYING(250), vypocet54 CHARACTER VARYING(250), vypocet55 CHARACTER VARYING(250), vypocet56 CHARACTER VARYING(250), vypocet57 CHARACTER VARYING(250), vypocet58 CHARACTER VARYING(250), vypocet59 CHARACTER VARYING(250), vypocet60 CHARACTER VARYING(250), vypocet61 CHARACTER VARYING(250), vypocet62 CHARACTER VARYING(250), vypocet63 CHARACTER VARYING(250), vypocet64 CHARACTER VARYING(250), vypocet65 CHARACTER VARYING(250), vypocet66 CHARACTER VARYING(250), vypocet67 CHARACTER VARYING(250), vypocet68 CHARACTER VARYING(250), vypocet69 CHARACTER VARYING(250), vypocet70 CHARACTER VARYING(250), vypocet71 CHARACTER VARYING(250), vypocet72 CHARACTER VARYING(250), vypocet73 CHARACTER VARYING(250), vypocet74 CHARACTER VARYING(250), vypocet75 CHARACTER VARYING(250), vypocet76 CHARACTER VARYING(250), vypocet77 CHARACTER VARYING(250), vypocet78 CHARACTER VARYING(250), vypocet79 CHARACTER VARYING(250), vypocet80 CHARACTER VARYING(250), vypocet81 CHARACTER VARYING(250), vypocet82 CHARACTER VARYING(250), vypocet83 CHARACTER VARYING(250), vypocet84 CHARACTER VARYING(250), vypocet85 CHARACTER VARYING(250), vypocet86 CHARACTER VARYING(250), vypocet87 CHARACTER VARYING(250), vypocet88 CHARACTER VARYING(250), vypocet89 CHARACTER VARYING(250), vypocet90 CHARACTER VARYING(250), vypocet91 CHARACTER VARYING(250), vypocet92 CHARACTER VARYING(250), vypocet93 CHARACTER VARYING(250), vypocet94 CHARACTER VARYING(250), vypocet95 CHARACTER VARYING(250), vypocet96 CHARACTER VARYING(250), vypocet97 CHARACTER VARYING(250), vypocet98 CHARACTER VARYING(250), vypocet99 CHARACTER VARYING(250), idriadok INTEGER) ;
							ALTER TABLE food600.vypocty ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.vypocty;
							SELECT nextval('food600.vypocty_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.vypocty_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.vypocty_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='food_dat' THEN
							ALTER TABLE food600.food_dat DISABLE TRIGGER ALL;
							TRUNCATE food600.food_dat RESTART IDENTITY;
							INSERT INTO food600.food_dat(id, id_menu, pgm, pgm_param, pgm_path, dat_path, cen_path, c_data, id_zkratka, c_stredisk, priority, skupina, comment, bour_skup, setup_skup, prava_skup, stredskup, a1, a2, a3, a4, a5, a6, a7, a8, a9, b1, b2, b3, b4, b5, b6, b7, b8, b9, c1, c2, c3, c4, c5, c6, c7, c8, c9, id_klapky, pozadi, defa_prn, zadan_prn, era_cen, typ_inst, kont_dbf, sankcnicen, master_kas, plateny, servis, edi_kod, id_prev, prevadzka, eet_dic, eet_dic2, eet_provoz, eet_kasa, eet_url, eet_url2, id_ediprev, idmaster, datinst)
								SELECT id, id_menu, pgm, pgm_param, pgm_path, dat_path, cen_path, c_data, id_zkratka, c_stredisk, priority, skupina, comment, bour_skup, setup_skup, prava_skup, stredskup, a1, a2, a3, a4, a5, a6, a7, a8, a9, b1, b2, b3, b4, b5, b6, b7, b8, b9, c1, c2, c3, c4, c5, c6, c7, c8, c9, id_klapky, pozadi, defa_prn, zadan_prn, era_cen, typ_inst, kont_dbf, sankcnicen, master_kas, plateny, servis, edi_kod, id_prev, prevadzka, eet_dic, eet_dic2, eet_provoz, eet_kasa, eet_url, eet_url2, id_ediprev, id as idmaster, datinst FROM dblink('connstrx','SELECT id, id_menu, pgm, pgm_param, pgm_path, dat_path, cen_path, c_data, id_zkratka, c_stredisk, priority, skupina, comment, bour_skup, setup_skup, prava_skup, stredskup, a1, a2, a3, a4, a5, a6, a7, a8, a9, b1, b2, b3, b4, b5, b6, b7, b8, b9, c1, c2, c3, c4, c5, c6, c7, c8, c9, id_klapky, pozadi, defa_prn, zadan_prn, era_cen, typ_inst, kont_dbf, sankcnicen, master_kas, plateny, servis, edi_kod, id_prev, prevadzka, eet_dic, eet_dic2, eet_provoz, eet_kasa, eet_url, eet_url2, id_ediprev, datinst FROM food600.food_dat ORDER BY id') 
								 as remzmeny(id CHARACTER(2), id_menu CHARACTER(10), pgm CHARACTER(12), pgm_param CHARACTER(12), pgm_path CHARACTER(30), dat_path CHARACTER(30), cen_path CHARACTER(30), c_data INTEGER, id_zkratka CHARACTER(30), c_stredisk INTEGER, priority INTEGER, skupina CHARACTER(1), comment CHARACTER(50), bour_skup CHARACTER(2), setup_skup CHARACTER(2), prava_skup CHARACTER(2), stredskup CHARACTER(4), a1 CHARACTER(2), a2 CHARACTER(2), a3 CHARACTER(2), a4 CHARACTER(2), a5 CHARACTER(2), a6 CHARACTER(2), a7 CHARACTER(2), a8 CHARACTER(2), a9 CHARACTER(2), b1 CHARACTER(2), b2 CHARACTER(2), b3 CHARACTER(2), b4 CHARACTER(2), b5 CHARACTER(2), b6 CHARACTER(2), b7 CHARACTER(2), b8 CHARACTER(2), b9 CHARACTER(2), c1 CHARACTER(2), c2 CHARACTER(2), c3 CHARACTER(2), c4 CHARACTER(2), c5 CHARACTER(2), c6 CHARACTER(2), c7 CHARACTER(2), c8 CHARACTER(2), c9 CHARACTER(2), id_klapky CHARACTER(2), pozadi CHARACTER(30), defa_prn CHARACTER(2), zadan_prn CHARACTER(2), era_cen CHARACTER(5), typ_inst INTEGER, kont_dbf SMALLINT, sankcnicen CHARACTER(2), master_kas CHARACTER(2), plateny SMALLINT, servis SMALLINT, edi_kod CHARACTER(15), id_prev CHARACTER(2), prevadzka CHARACTER(30), eet_dic CHARACTER(12), eet_dic2 CHARACTER(12), eet_provoz CHARACTER(10), eet_kasa CHARACTER(10), eet_url CHARACTER(99), eet_url2 CHARACTER(99), id_ediprev INTEGER, datinst DATE) ;
							ALTER TABLE food600.food_dat ENABLE TRIGGER ALL;
						WHEN btrim(mtabulka)='kl_don' THEN
							ALTER TABLE food600.kl_don DISABLE TRIGGER ALL;
							TRUNCATE food600.kl_don RESTART IDENTITY;
							INSERT INTO food600.kl_don(strana, pozice, caption, typ, vazba, caption1, caption2, caption3, caption4, c_data, c_karty, umisteno, id, idriadok, idriadok_master)
								SELECT strana, pozice, caption, typ, vazba, caption1, caption2, caption3, caption4, c_data, c_karty, umisteno, id, idriadok, idriadok as idriadok_master FROM dblink('connstrx','SELECT strana, pozice, caption, typ, vazba, caption1, caption2, caption3, caption4, c_data, c_karty, umisteno, id, idriadok FROM food600.kl_don ORDER BY idriadok') 
								as remzmeny(strana BIGINT, pozice BIGINT, caption CHARACTER(30), typ CHARACTER(4), vazba BIGINT, caption1 CHARACTER(30), caption2 CHARACTER(30), caption3 CHARACTER(30), caption4 CHARACTER(30), c_data INTEGER, c_karty INTEGER, umisteno INTEGER, id CHARACTER(2), idriadok INTEGER) ;
							ALTER TABLE food600.kl_don ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.kl_don;
							SELECT nextval('food600.kl_don_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.kl_don_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.kl_don_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='klapky' THEN
							ALTER TABLE food600.klapky DISABLE TRIGGER ALL;
							TRUNCATE food600.klapky RESTART IDENTITY;
							INSERT INTO food600.klapky(strana, pozice, caption, typ, vazba, colo, barva, autonavrat, caption1, caption2, caption3, caption4, velk_klp, c_data, c_karty, umisteno, id, idriadok, mod, oblast, hore, vyska, font_size, font_name, idriadok_master)
								SELECT strana, pozice, caption, typ, vazba, colo, barva, autonavrat, caption1, caption2, caption3, caption4, velk_klp, c_data, c_karty, umisteno, id, idriadok, mod, oblast, hore, vyska, font_size, font_name, idriadok as idriadok_master FROM dblink('connstrx','SELECT strana, pozice, caption, typ, vazba, colo, barva, autonavrat, caption1, caption2, caption3, caption4, velk_klp, c_data, c_karty, umisteno, id, idriadok, mod, oblast, hore, vyska, font_size, font_name FROM food600.klapky ORDER BY idriadok') 
								as remzmeny(strana BIGINT, pozice BIGINT, caption CHARACTER(30), typ CHARACTER(4), vazba BIGINT, colo BIGINT, barva CHARACTER(10), autonavrat CHARACTER(1), caption1 CHARACTER(30), caption2 CHARACTER(30), caption3 CHARACTER(30), caption4 CHARACTER(30), velk_klp NUMERIC(1,0), c_data INTEGER, c_karty INTEGER, umisteno INTEGER, id CHARACTER(2), idriadok INTEGER, mod CHARACTER(1), oblast CHARACTER(1), hore INTEGER, vyska INTEGER, font_size NUMERIC(5,1), font_name CHARACTER(30)) ;
							ALTER TABLE food600.klapky ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.klapky;
							SELECT nextval('food600.klapky_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.klapky_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.klapky_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='klapkyn' THEN
							ALTER TABLE food600.klapkyn DISABLE TRIGGER ALL;
							TRUNCATE food600.klapkyn RESTART IDENTITY;
							INSERT INTO food600.klapkyn(strana, pozice, stlpec, riadok, caption, typ, vazba, colo, barva, autonavrat, caption1, caption2, caption3, caption4, velk_klp, c_data, c_karty, umisteno, id, idriadok, mod, oblast, hore, vyska, strom, idriadok_master)
								SELECT strana, pozice, stlpec, riadok, caption, typ, vazba, colo, barva, autonavrat, caption1, caption2, caption3, caption4, velk_klp, c_data, c_karty, umisteno, id, idriadok, mod, oblast, hore, vyska, strom, idriadok as idriadok_master FROM dblink('connstrx','SELECT strana, pozice, stlpec, riadok, caption, typ, vazba, colo, barva, autonavrat, caption1, caption2, caption3, caption4, velk_klp, c_data, c_karty, umisteno, id, idriadok, mod, oblast, hore, vyska, strom FROM food600.klapkyn ORDER BY idriadok') 
								as remzmeny(strana BIGINT, pozice BIGINT, stlpec BIGINT, riadok BIGINT, caption CHARACTER(30), typ CHARACTER(4), vazba BIGINT, colo BIGINT, barva CHARACTER(10), autonavrat CHARACTER(1), caption1 CHARACTER(30), caption2 CHARACTER(30), caption3 CHARACTER(30), caption4 CHARACTER(30), velk_klp NUMERIC(2,0), c_data INTEGER, c_karty INTEGER, umisteno INTEGER, id CHARACTER(2), idriadok INTEGER, mod CHARACTER(1), oblast CHARACTER(1), hore INTEGER, vyska INTEGER, strom SMALLINT) ;
							ALTER TABLE food600.klapkyn ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.klapkyn;
							SELECT nextval('food600.klapkyn_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.klapkyn_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.klapkyn_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='obaly' THEN
							ALTER TABLE food600.obaly DISABLE TRIGGER ALL;
							TRUNCATE food600.obaly RESTART IDENTITY CASCADE;
							INSERT INTO food600.obaly(nazev, hmotnost, obrazok, c_karty, c_data, idriadok, idriadok_master)
								SELECT nazev, hmotnost, obrazok, c_karty, c_data, idriadok, idriadok AS idriadok_master  FROM dblink('connstrx','SELECT nazev, hmotnost, obrazok, c_karty, c_data, idriadok FROM food600.obaly ORDER BY idriadok') 
								as remzmeny(nazev CHARACTER(50), hmotnost NUMERIC(10,3), obrazok BYTEA, c_karty INTEGER, c_data SMALLINT, idriadok INTEGER);
							ALTER TABLE food600.obaly ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.obaly;
							SELECT nextval('food600.obaly_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.obaly_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.obaly_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='obaly_kasa' THEN
							ALTER TABLE food600.obaly_kasa DISABLE TRIGGER ALL;
							TRUNCATE food600.obaly_kasa RESTART IDENTITY;
							INSERT INTO food600.obaly_kasa(id_kas, c_obal, poradie, idriadok, idriadok_master)
								SELECT id_kas, c_obal, poradie, idriadok, idriadok AS idriadok_master  FROM dblink('connstrx','SELECT id_kas, c_obal, poradie, idriadok FROM food600.obaly_kasa ORDER BY idriadok') 
								as remzmeny(id_kas CHARACTER(2), c_obal INTEGER, poradie SMALLINT, idriadok INTEGER);
							ALTER TABLE food600.obaly_kasa ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.obaly_kasa;
							SELECT nextval('food600.obaly_kasa_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.obaly_kasa_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.obaly_kasa_idriadok_seq', 1, true);
								END IF;
							END IF;
						WHEN btrim(mtabulka)='obaly_kasa_karta' THEN
							ALTER TABLE food600.obaly_kasa_karta DISABLE TRIGGER ALL;
							TRUNCATE food600.obaly_kasa_karta RESTART IDENTITY;
							INSERT INTO food600.obaly_kasa_karta(id_kas, c_obal, poradie, sosebou, c_karty, idriadok, idriadok_master)
								SELECT id_kas, c_obal, poradie, sosebou, c_karty, idriadok, idriadok AS idriadok_master  FROM dblink('connstrx','SELECT id_kas, c_obal, poradie, sosebou, c_karty, idriadok FROM food600.obaly_kasa_karta ORDER BY idriadok') 
								as remzmeny(id_kas CHARACTER(2), c_obal INTEGER, poradie SMALLINT, sosebou SMALLINT, c_karty INTEGER, idriadok INTEGER);
							ALTER TABLE food600.obaly_kasa_karta ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.obaly_kasa_karta;
							SELECT nextval('food600.obaly_kasa_karta_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.obaly_kasa_karta_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.obaly_kasa_karta_idriadok_seq', 1, true);
								END IF;
							END IF;
						-- L.L. (03.09.2021)
						WHEN btrim(mtabulka)='obj_stravy' THEN
							ALTER TABLE food600.obj_stravy DISABLE TRIGGER ALL;
							TRUNCATE food600.obj_stravy RESTART IDENTITY;
							INSERT INTO food600.obj_stravy(idriadok, id_karty, id_ucet, id_limit, id_den, id_rov, dieta, skupina, poradie, pocet, prenesene, vydane, dat_vyd, dat_obj, dat_pren, cena, idriadok_master)
								SELECT idriadok, id_karty, id_ucet, id_limit, id_den, id_rov, dieta, skupina, poradie, pocet, prenesene, vydane, dat_vyd, dat_obj, dat_pren, cena, idriadok as idriadok_master FROM 
									dblink('connstrx','SELECT idriadok, id_karty, id_ucet, id_limit, id_den, id_rov, dieta, skupina, poradie, pocet, prenesene, vydane, dat_vyd, dat_obj, dat_pren, cena FROM food600.obj_stravy ORDER BY idriadok') 																		
									as remzmeny(idriadok INTEGER, id_karty INTEGER, id_ucet INTEGER, id_limit INTEGER, id_den INTEGER, id_rov INTEGER, dieta CHARACTER(5), skupina CHARACTER(1), poradie CHARACTER(4), pocet NUMERIC(3,2), prenesene SMALLINT, vydane SMALLINT, dat_vyd TIMESTAMP WITHOUT TIME ZONE, dat_obj TIMESTAMP WITHOUT TIME ZONE, dat_pren TIMESTAMP WITHOUT TIME ZONE, cena NUMERIC(10,2)) ;														
							ALTER TABLE food600.obj_stravy ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM food600.obj_stravy;
							SELECT nextval('food600.obj_stravy_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('food600.obj_stravy_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('food600.obj_stravy_idriadok_seq', 1, true);
								END IF;
							END IF;
						-- L.L. (07.12.2021)
						WHEN btrim(mtabulka)='hk_typk' THEN
							ALTER TABLE kredit.hk_typk DISABLE TRIGGER ALL;
							TRUNCATE kredit.hk_typk RESTART IDENTITY CASCADE;
							INSERT INTO kredit.hk_typk(typ, popis, idriadok, hk_ptypk, zmazane, def_typ, platnost, bon_podla, id, strava_typ, idriadok_master)
								SELECT typ, popis, idriadok, hk_ptypk, zmazane, def_typ, platnost, bon_podla, id, strava_typ, idriadok as idriadok_master FROM 
									dblink('connstrx','SELECT typ, popis, idriadok, hk_ptypk, zmazane, def_typ, platnost, bon_podla, id, strava_typ FROM kredit.hk_typk ORDER BY idriadok') 																		
									as remzmeny(typ CHARACTER(1), popis CHARACTER(50), idriadok INTEGER, hk_ptypk SMALLINT, zmazane SMALLINT, def_typ SMALLINT, platnost INTEGER, bon_podla NUMERIC(2,0), id INTEGER, strava_typ INTEGER);
							ALTER TABLE kredit.hk_typk ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM kredit.hk_typk;
							SELECT nextval('kredit.hk_typk_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('kredit.hk_typk_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('kredit.hk_typk_idriadok_seq', 1, true);
								END IF;
							END IF;
						-- L.L. (13.12.2021)
						WHEN btrim(mtabulka)='hk_typk_operacie' THEN
							ALTER TABLE kredit.hk_typk_operacie DISABLE TRIGGER ALL;
							TRUNCATE kredit.hk_typk_operacie RESTART IDENTITY CASCADE;
							INSERT INTO kredit.hk_typk_operacie(typ, id_oper, idriadok, idriadok_master)
								SELECT typ, id_oper, idriadok, idriadok as idriadok_master FROM 
									dblink('connstrx','SELECT typ, id_oper, idriadok FROM kredit.hk_typk_operacie ORDER BY idriadok') 																		
									as remzmeny(typ CHARACTER(1), id_oper INTEGER, idriadok INTEGER);
							ALTER TABLE kredit.hk_typk_operacie ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM kredit.hk_typk_operacie;
							SELECT nextval('kredit.hk_typk_operacie_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('kredit.hk_typk_operacie_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('kredit.hk_typk_operacie_idriadok_seq', 1, true);
								END IF;
							END IF;
						-- L.L. (08.12.2021)
						WHEN btrim(mtabulka)='hk_operacie' THEN
							ALTER TABLE kredit.hk_operacie DISABLE TRIGGER ALL;
							TRUNCATE kredit.hk_operacie RESTART IDENTITY CASCADE;
							INSERT INTO kredit.hk_operacie(popis, povolene, skratka, id_oper, id_oper_master) 												
								SELECT popis, povolene, skratka, id_oper, id_oper as id_oper_master FROM 
									dblink('connstrx','SELECT popis, povolene, skratka, id_oper FROM kredit.hk_operacie ORDER BY id_oper') 																		
									as remzmeny(popis CHARACTER(50), povolene SMALLINT, skratka CHARACTER(3), id_oper INTEGER);
							ALTER TABLE kredit.hk_operacie ENABLE TRIGGER ALL;
							SELECT MAX(id_oper) into maxid FROM kredit.hk_operacie;
							SELECT nextval('kredit.hk_operacie_id_oper_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('kredit.hk_operacie_id_oper_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('kredit.hk_operacie_id_oper_seq', 1, true);
								END IF;
							END IF;											
						-- L.L. (08.12.2021)
						WHEN btrim(mtabulka)='orgstr' THEN
							ALTER TABLE kredit.orgstr DISABLE TRIGGER ALL;
							TRUNCATE kredit.orgstr RESTART IDENTITY CASCADE;
							INSERT INTO kredit.orgstr(maxperioda, nazov_org, adresa_org, dic_org, cenhl_org, druh_plat, typ_kred, typ_fakt, suhrn_org, doplat_1, typ_d1, nazov_d1, typ_d2, doplat_2, nazov_d2, doplat_3, typ_d3, nazov_d3, max_pocet, typ_obmedz, vlast_zar, zav_rest, kred_zlav, plat_dph, label, max_d2, max_d3, den_limit, co_menit, kedy_ns_kr, hod_ns_kr, mesto_org, psc_org, ico_org, b_ucet, banka, b_naz_uctu, b_adresa, telefon, fax, blokovana, zaokruhlit, kon_osoba, datum_zm, autor_zm, mena, zmazana, max_hl_jed, pr_pohyb, pr_zostato, pr_sp_dnes, pr_sp_mes, pr_zu_dnes, cislo_org, email, pr_zos_jed, pr_sp_jed, dob_bonper, dob_bonabs, id, cislo_org_master) 												
								SELECT maxperioda, nazov_org, adresa_org, dic_org, cenhl_org, druh_plat, typ_kred, typ_fakt, suhrn_org, doplat_1, typ_d1, nazov_d1, typ_d2, doplat_2, nazov_d2, doplat_3, typ_d3, nazov_d3, max_pocet, typ_obmedz, vlast_zar, zav_rest, kred_zlav, plat_dph, label, max_d2, max_d3, den_limit, co_menit, kedy_ns_kr, hod_ns_kr, mesto_org, psc_org, ico_org, b_ucet, banka, b_naz_uctu, b_adresa, telefon, fax, blokovana, zaokruhlit, kon_osoba, datum_zm, autor_zm, mena, zmazana, max_hl_jed, pr_pohyb, pr_zostato, pr_sp_dnes, pr_sp_mes, pr_zu_dnes, cislo_org, email, pr_zos_jed, pr_sp_jed, dob_bonper, dob_bonabs, id, cislo_org as cislo_org_master FROM	
									dblink('connstrx','SELECT maxperioda, nazov_org, adresa_org, dic_org, cenhl_org, druh_plat, typ_kred, typ_fakt, suhrn_org, doplat_1, typ_d1, nazov_d1, typ_d2, doplat_2, nazov_d2, doplat_3, typ_d3, nazov_d3, max_pocet, typ_obmedz, vlast_zar, zav_rest, kred_zlav, plat_dph, label, max_d2, max_d3, den_limit, co_menit, kedy_ns_kr, hod_ns_kr, mesto_org, psc_org, ico_org, b_ucet, banka, b_naz_uctu, b_adresa, telefon, fax, blokovana, zaokruhlit, kon_osoba, datum_zm, autor_zm, mena, zmazana, max_hl_jed, pr_pohyb, pr_zostato, pr_sp_dnes, pr_sp_mes, pr_zu_dnes, cislo_org, email, pr_zos_jed, pr_sp_jed, dob_bonper, dob_bonabs, id FROM kredit.orgstr ORDER BY cislo_org') 																		
									as remzmeny(maxperioda CHARACTER(1), nazov_org CHARACTER(30), adresa_org CHARACTER(25), dic_org CHARACTER(15), cenhl_org CHARACTER(1), druh_plat CHARACTER(8), typ_kred CHARACTER(1), typ_fakt CHARACTER(1), suhrn_org  CHARACTER(2), doplat_1 NUMERIC(5,2), typ_d1 CHARACTER(1), nazov_d1 CHARACTER(10), typ_d2 CHARACTER(1), doplat_2  NUMERIC(5,2), nazov_d2 CHARACTER(10), doplat_3 NUMERIC(5,2), typ_d3 CHARACTER(1), nazov_d3 CHARACTER(10), max_pocet NUMERIC(2,0), typ_obmedz CHARACTER(10), vlast_zar CHARACTER(1), zav_rest CHARACTER(1), kred_zlav NUMERIC(5,2), plat_dph CHARACTER(1), label SMALLINT, max_d2 NUMERIC(7,2), max_d3 NUMERIC(7,2), den_limit NUMERIC(9,2), co_menit CHARACTER(10), kedy_ns_kr CHARACTER(10), hod_ns_kr NUMERIC(9,2), mesto_org CHARACTER(25), psc_org CHARACTER(6), ico_org CHARACTER(8), b_ucet CHARACTER(25), banka  CHARACTER(6), b_naz_uctu  CHARACTER(25), b_adresa  CHARACTER(18), telefon  CHARACTER(25), fax  CHARACTER(25), blokovana SMALLINT, zaokruhlit CHARACTER(10), kon_osoba CHARACTER(35), datum_zm  TIMESTAMP WITHOUT TIME ZONE, autor_zm CHARACTER(3), mena CHARACTER(3), zmazana SMALLINT, max_hl_jed NUMERIC(1,0), pr_pohyb SMALLINT, pr_zostato SMALLINT, pr_sp_dnes SMALLINT, pr_sp_mes SMALLINT, pr_zu_dnes SMALLINT, cislo_org INTEGER, email CHARACTER(50), pr_zos_jed SMALLINT, pr_sp_jed SMALLINT, dob_bonper NUMERIC(6,2), dob_bonabs NUMERIC(6,2), id INTEGER);
							ALTER TABLE kredit.orgstr ENABLE TRIGGER ALL;
							SELECT MAX(cislo_org) into maxid FROM kredit.orgstr;
							SELECT nextval('kredit.orgstr_cislo_org_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('kredit.orgstr_cislo_org_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('kredit.orgstr_cislo_org_seq', 1, true);
								END IF;
							END IF;							
						-- L.L. (10.12.2021)
						WHEN btrim(mtabulka)='hot_kred' THEN
							ALTER TABLE kredit.hot_kred DISABLE TRIGGER ALL;
							TRUNCATE kredit.hot_kred RESTART IDENTITY CASCADE;
							INSERT INTO kredit.hot_kred(datcas, priezvisko, meno, tel_domu, tel_office, tel_gsm, email, ulica, mesto, psc, pr_pozice, kredit, typ, exp_date, limit_kred, limit_var, limit_den, sl_koef, sl_limit, sl_lim_mes, autor, storno, st_datum, prichod, cis_fak, max_d_odb, last_d_odb, last_dat_o, typ_slevy, k_vyplate, skupina, default_s, default_o, default_v, label, last_j, smazana, sledovanie, vst_den, mena, cislo_org, typ_email, c_hlad, ulica_zam, mesto_zam, psc_zam, id_ucet, id, zmena, izba, account_id, id_hores, dieta, stol, stolicka, miestnost, id_ucet_master)
								SELECT datcas, priezvisko, meno, tel_domu, tel_office, tel_gsm, email, ulica, mesto, psc, pr_pozice, kredit, typ, exp_date, limit_kred, limit_var, limit_den, sl_koef, sl_limit, sl_lim_mes, autor, storno, st_datum, prichod, cis_fak, max_d_odb, last_d_odb, last_dat_o, typ_slevy, k_vyplate, skupina, default_s, default_o, default_v, label, last_j, smazana, sledovanie, vst_den, mena, cislo_org, typ_email, c_hlad, ulica_zam, mesto_zam, psc_zam, id_ucet, id, zmena, izba, account_id, id_hores, dieta, stol, stolicka, miestnost, id_ucet as id_ucet_master FROM									
									dblink('connstrx','SELECT datcas, priezvisko, meno, tel_domu, tel_office, tel_gsm, email, ulica, mesto, psc, pr_pozice, kredit, typ, exp_date, limit_kred, limit_var, limit_den, sl_koef, sl_limit, sl_lim_mes, autor, storno, st_datum, prichod, cis_fak, max_d_odb, last_d_odb, last_dat_o, typ_slevy, k_vyplate, skupina, default_s, default_o, default_v, label, last_j, smazana, sledovanie, vst_den, mena, cislo_org, typ_email, c_hlad, ulica_zam, mesto_zam, psc_zam, id_ucet, id, zmena, izba, account_id, id_hores, dieta, stol, stolicka, miestnost FROM kredit.hot_kred ORDER BY id_ucet')
									as remzmeny(datcas TIMESTAMP WITHOUT TIME ZONE, priezvisko CHARACTER(30), meno  CHARACTER(30), tel_domu CHARACTER(20), tel_office CHARACTER(20), tel_gsm CHARACTER(20), email CHARACTER(40), ulica CHARACTER(40), mesto CHARACTER(40), psc CHARACTER(5), pr_pozice CHARACTER(20), kredit NUMERIC(9,2), typ  CHARACTER(1), exp_date DATE , limit_kred NUMERIC(9,2), limit_var NUMERIC(9,2), limit_den NUMERIC(9,2), sl_koef NUMERIC(4,2), sl_limit NUMERIC(8,2), sl_lim_mes NUMERIC(9,2), autor CHARACTER(3), storno SMALLINT, st_datum DATE, prichod CHARACTER(14), cis_fak NUMERIC(10,0), max_d_odb NUMERIC(1,0), last_d_odb NUMERIC(3,0), last_dat_o DATE, typ_slevy NUMERIC(2,0), k_vyplate CHARACTER(1), skupina CHARACTER(1), default_s CHARACTER(1), default_o CHARACTER(1), default_v CHARACTER(1), label SMALLINT, last_j CHARACTER(1), smazana SMALLINT, sledovanie CHARACTER(1), vst_den NUMERIC(4,0), mena CHARACTER(3), cislo_org INTEGER, typ_email NUMERIC(1,0), c_hlad CHARACTER(2), ulica_zam CHARACTER(50), mesto_zam CHARACTER(50), psc_zam CHARACTER(5), id_ucet INTEGER, id INTEGER, zmena TIMESTAMP WITHOUT TIME ZONE, izba CHARACTER(5), account_id INTEGER, id_hores INTEGER, dieta CHARACTER(5), stol CHARACTER(10), stolicka INTEGER, miestnost CHARACTER(30));
							ALTER TABLE kredit.hot_kred ENABLE TRIGGER ALL;
							SELECT MAX(id_ucet) into maxid FROM kredit.hot_kred;
							SELECT nextval('kredit.hot_kred_id_ucet_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('kredit.hot_kred_id_ucet_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('kredit.hot_kred_id_ucet_seq', 1, true);
								END IF;
							END IF;													
						-- L.L. (10.12.2021)
						WHEN btrim(mtabulka)='hk_oskar' THEN
							ALTER TABLE kredit.hk_oskar DISABLE TRIGGER ALL;
							TRUNCATE kredit.hk_oskar RESTART IDENTITY CASCADE;
							INSERT INTO kredit.hk_oskar(cis_kred, id_ucet, datumod, datumdo, storno, priezvisko, meno, blok, exp_date, platneako, rod_cis, dat_naroz, dat_svatek, id_karty, ident, id, zmena, id_karty_master)							 
								SELECT cis_kred, id_ucet, datumod, datumdo, storno, priezvisko, meno, blok, exp_date, platneako, rod_cis, dat_naroz, dat_svatek, id_karty, ident, id, zmena, id_karty as id_karty_master FROM									
									dblink('connstrx','SELECT cis_kred, id_ucet, datumod, datumdo, storno, priezvisko, meno, blok, exp_date, platneako, rod_cis, dat_naroz, dat_svatek, id_karty, ident, id, zmena FROM kredit.hk_oskar ORDER BY id_karty')
									as remzmeny(cis_kred CHARACTER(20), id_ucet INTEGER, datumod TIMESTAMP WITHOUT TIME ZONE, datumdo TIMESTAMP WITHOUT TIME ZONE, storno SMALLINT, priezvisko CHARACTER(50), meno CHARACTER(50), blok SMALLINT, exp_date DATE, platneako SMALLINT, rod_cis CHARACTER(11), dat_naroz DATE, dat_svatek CHARACTER(6), id_karty INTEGER, ident CHARACTER(40), id INTEGER, zmena TIMESTAMP WITHOUT TIME ZONE);
							ALTER TABLE kredit.hk_oskar ENABLE TRIGGER ALL;
							SELECT MAX(id_ucet) into maxid FROM kredit.hk_oskar;
							SELECT nextval('kredit.hk_oskar_id_karty_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('kredit.hk_oskar_id_karty_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('kredit.hk_oskar_id_karty_seq', 1, true);
								END IF;
							END IF;							
						-- L.L. (10.12.2021)
						WHEN btrim(mtabulka)='hkredobr' THEN
							ALTER TABLE kredit.hkredobr DISABLE TRIGGER ALL;
							TRUNCATE kredit.hkredobr RESTART IDENTITY CASCADE;
							INSERT INTO kredit.hkredobr(datcas, u_cis, uzaverka, id_ucet, castka, body, id_oper, sl_chlad, sl_proc, autor, puv_u_cis, puv_uzav, mena, poc_hl_jed, cislo_org, c_dopl, c_dopl_m, poc_menu, idriadok, id_karty, bonus, id_kredit, id_local, zmena, id_sync, rupdate, id_limit, id_den, id_rov, idriadok_master)							 
								SELECT datcas, u_cis, uzaverka, id_ucet, castka, body, id_oper, sl_chlad, sl_proc, autor, puv_u_cis, puv_uzav, mena, poc_hl_jed, cislo_org, c_dopl, c_dopl_m, poc_menu, idriadok, id_karty, bonus, id_kredit, id_local, zmena, id_sync, rupdate, id_limit, id_den, id_rov, idriadok as idriadok_master FROM									
									dblink('connstrx','SELECT datcas, u_cis, uzaverka, id_ucet, castka, body, id_oper, sl_chlad, sl_proc, autor, puv_u_cis, puv_uzav, mena, poc_hl_jed, cislo_org, c_dopl, c_dopl_m, poc_menu, idriadok, id_karty, bonus, id_kredit, id_local, zmena, id_sync, rupdate, id_limit, id_den, id_rov FROM kredit.hkredobr ORDER BY idriadok')
									as remzmeny(datcas TIMESTAMP WITHOUT TIME ZONE, u_cis CHARACTER(7), uzaverka CHARACTER(17), id_ucet INTEGER, castka NUMERIC(9,2), body NUMERIC(9,2), id_oper INTEGER, sl_chlad NUMERIC(9,2),
									sl_proc NUMERIC(9,2), autor CHARACTER(3), puv_u_cis CHARACTER(7), puv_uzav CHARACTER(17), mena CHARACTER(3), poc_hl_jed NUMERIC(8,4), cislo_org INTEGER, c_dopl NUMERIC(12,2), c_dopl_m NUMERIC(12,2), 
									poc_menu NUMERIC(8,2), idriadok INTEGER, id_karty INTEGER, bonus NUMERIC(9,2), id_kredit INTEGER, id_local INTEGER, zmena TIMESTAMP WITHOUT TIME ZONE, id_sync INTEGER, rupdate TIMESTAMP WITHOUT TIME ZONE, id_limit INTEGER, id_den INTEGER, id_rov INTEGER);
							ALTER TABLE kredit.hkredobr ENABLE TRIGGER ALL;
							SELECT MAX(id_ucet) into maxid FROM kredit.hkredobr;
							SELECT nextval('kredit.hkredobr_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('kredit.hkredobr_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('kredit.hkredobr_idriadok_seq', 1, true);
								END IF;
							END IF;							
						-- L.L. (14.12.2021)
						WHEN btrim(mtabulka)='hk_ptypk' THEN
							ALTER TABLE kredit.hk_ptypk DISABLE TRIGGER ALL;
							TRUNCATE kredit.hk_ptypk RESTART IDENTITY CASCADE;
							INSERT INTO kredit.hk_ptypk(idriadok, typ, id_oper, id_kas, mesiace, dni, datum_do, cas_od, cas_do, castka, zustatek, sl_koef, c_hlad, popis, prep_koef, zaokruhlit, poradie, tlaciaren, sucast_uct, skrat_mena, mena, sled_poc_j, abs_bon, datum_od, pri_slenie, id, idriadok_master)						
								SELECT idriadok, typ, id_oper, id_kas, mesiace, dni, datum_do, cas_od, cas_do, castka, zustatek, sl_koef, c_hlad, popis, prep_koef, zaokruhlit, poradie, tlaciaren, sucast_uct, skrat_mena, mena, sled_poc_j, abs_bon, datum_od, pri_slenie, id, idriadok as idriadok_master FROM								
									dblink('connstrx','SELECT idriadok, typ, id_oper, id_kas, mesiace, dni, datum_do, cas_od, cas_do, castka, zustatek, sl_koef, c_hlad, popis, prep_koef, zaokruhlit, poradie, tlaciaren, sucast_uct, skrat_mena, mena, sled_poc_j, abs_bon, datum_od, pri_slenie, id FROM kredit.hk_ptypk ORDER BY idriadok') 																		
									as remzmeny(idriadok INTEGER, typ CHARACTER(1), id_oper SMALLINT, id_kas CHARACTER(3), mesiace CHARACTER(12), dni CHARACTER(7), datum_do DATE, cas_od CHARACTER(8), cas_do CHARACTER(8), 
									castka NUMERIC(10,2) , zustatek NUMERIC(10,2), sl_koef NUMERIC(5,2), c_hlad CHARACTER(1), popis CHARACTER(20), prep_koef NUMERIC(4,2), zaokruhlit NUMERIC(2,0), poradie SMALLINT, tlaciaren CHARACTER(2), sucast_uct SMALLINT, skrat_mena CHARACTER(6), mena CHARACTER(3), sled_poc_j SMALLINT, abs_bon NUMERIC(11,2), datum_od DATE, pri_slenie SMALLINT, id INTEGER);
							ALTER TABLE kredit.hk_ptypk ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM kredit.hk_ptypk;
							SELECT nextval('kredit.hk_ptypk_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('kredit.hk_ptypk_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('kredit.hk_ptypk_idriadok_seq', 1, true);
								END IF;
							END IF;
						-- L.L. (17.12.2021)
						WHEN btrim(mtabulka)='hk_ptypk_druh_pl' THEN
							ALTER TABLE kredit.hk_ptypk_druh_pl DISABLE TRIGGER ALL;
							TRUNCATE kredit.hk_ptypk_druh_pl RESTART IDENTITY CASCADE;
							INSERT INTO kredit.hk_ptypk_druh_pl(idriadok, ptypkidriadok, druh_pl, c_druhpl, idriadok_master)						
								SELECT idriadok, ptypkidriadok, druh_pl, c_druhpl, idriadok as idriadok_master FROM								
									dblink('connstrx','SELECT idriadok, ptypkidriadok, druh_pl, c_druhpl FROM kredit.hk_ptypk_druh_pl ORDER BY idriadok') 																		
									as remzmeny(idriadok INTEGER, ptypkidriadok BIGINT, druh_pl CHARACTER(8), c_druhpl INTEGER);									
							ALTER TABLE kredit.hk_ptypk_druh_pl ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM kredit.hk_ptypk_druh_pl;
							SELECT nextval('kredit.hk_ptypk_druh_pl_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('kredit.hk_ptypk_druh_pl_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('kredit.hk_ptypk_druh_pl_idriadok_seq', 1, true);
								END IF;
							END IF;
						-- L.L. (20.02.2021)
						WHEN btrim(mtabulka)='hk_slevy' THEN
							ALTER TABLE kredit.hk_slevy DISABLE TRIGGER ALL;
							TRUNCATE kredit.hk_slevy RESTART IDENTITY CASCADE;
							INSERT INTO kredit.hk_slevy(idriadok, typ_slevy, popis, prikaz, povolene, def_typ, id, idriadok_master)						
								SELECT idriadok, typ_slevy, popis, prikaz, povolene, def_typ, id, idriadok as idriadok_master FROM								
									dblink('connstrx','SELECT idriadok, typ_slevy, popis, prikaz, povolene, def_typ, id FROM kredit.hk_slevy ORDER BY idriadok') 																		
									as remzmeny(idriadok INTEGER, typ_slevy NUMERIC(2,0), popis CHARACTER(15),  prikaz CHARACTER(50), povolene SMALLINT, def_typ SMALLINT, id SMALLINT);																	
							ALTER TABLE kredit.hk_slevy ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM kredit.hk_slevy;
							SELECT nextval('kredit.hk_slevy_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('kredit.hk_slevy_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('kredit.hk_slevy_idriadok_seq', 1, true);
								END IF;
							END IF;
						-- L.L. (20.12.2021)
						WHEN btrim(mtabulka)='hk_ptypk_spart' THEN
							ALTER TABLE kredit.hk_ptypk_spart DISABLE TRIGGER ALL;
							TRUNCATE kredit.hk_ptypk_spart RESTART IDENTITY CASCADE;
							INSERT INTO kredit.hk_ptypk_spart(idriadok, ptypkidriadok, spart, c_raster, idriadok_master)						
								SELECT idriadok, ptypkidriadok, spart, c_raster, idriadok as idriadok_master FROM								
									dblink('connstrx','SELECT idriadok, ptypkidriadok, spart, c_raster FROM kredit.hk_ptypk_spart ORDER BY idriadok') 																		
									as remzmeny(idriadok INTEGER, ptypkidriadok BIGINT, spart CHARACTER(8), c_raster INTEGER);									
							ALTER TABLE kredit.hk_ptypk_spart ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM kredit.hk_ptypk_spart;
							SELECT nextval('kredit.hk_ptypk_spart_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('kredit.hk_ptypk_spart_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('kredit.hk_ptypk_spart_idriadok_seq', 1, true);
								END IF;
							END IF;
						-- L.L. (20.12.2021)
						WHEN btrim(mtabulka)='hk_ptypk_zakaz_drpl' THEN
							ALTER TABLE kredit.hk_ptypk_zakaz_drpl DISABLE TRIGGER ALL;
							TRUNCATE kredit.hk_ptypk_zakaz_drpl RESTART IDENTITY CASCADE;
							INSERT INTO kredit.hk_ptypk_zakaz_drpl(idriadok, ptypkidriadok, druh_pl, c_druhpl, idriadok_master)						
								SELECT idriadok, ptypkidriadok, druh_pl, c_druhpl, idriadok as idriadok_master FROM								
									dblink('connstrx','SELECT idriadok, ptypkidriadok, druh_pl, c_druhpl FROM kredit.hk_ptypk_zakaz_drpl ORDER BY idriadok') 																		
									as remzmeny(idriadok INTEGER, ptypkidriadok BIGINT, druh_pl CHARACTER(8), c_druhpl INTEGER);									
							ALTER TABLE kredit.hk_ptypk_zakaz_drpl ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM kredit.hk_ptypk_zakaz_drpl;
							SELECT nextval('kredit.hk_ptypk_zakaz_drpl_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('kredit.hk_ptypk_zakaz_drpl_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('kredit.hk_ptypk_zakaz_drpl_idriadok_seq', 1, true);
								END IF;
							END IF;
						-- L.L. (20.12.2021)
						WHEN btrim(mtabulka)='hk_ptypk_zakaz_oper' THEN
							ALTER TABLE kredit.hk_ptypk_zakaz_oper DISABLE TRIGGER ALL;
							TRUNCATE kredit.hk_ptypk_zakaz_oper RESTART IDENTITY CASCADE;
							INSERT INTO kredit.hk_ptypk_zakaz_oper(idriadok, ptypkidriadok, id_oper, idriadok_master)						
								SELECT idriadok, ptypkidriadok, id_oper, idriadok as idriadok_master FROM								
									dblink('connstrx','SELECT idriadok, ptypkidriadok, id_oper FROM kredit.hk_ptypk_zakaz_oper ORDER BY idriadok') 																		
									as remzmeny(idriadok INTEGER, ptypkidriadok BIGINT, id_oper SMALLINT);									
							ALTER TABLE kredit.hk_ptypk_zakaz_oper ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM kredit.hk_ptypk_zakaz_oper;
							SELECT nextval('kredit.hk_ptypk_zakaz_oper_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('kredit.hk_ptypk_zakaz_oper_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('kredit.hk_ptypk_zakaz_oper_idriadok_seq', 1, true);
								END IF;
							END IF;
						-- L.L. (21.12.2021)
						WHEN btrim(mtabulka)='hk_sj_hlav' THEN
							ALTER TABLE kredit.hk_sj_hlav DISABLE TRIGGER ALL;
							TRUNCATE kredit.hk_sj_hlav RESTART IDENTITY CASCADE;
							INSERT INTO kredit.hk_sj_hlav(idriadok, c_kasy, meno, aktivna, zmazana, den1, den2, den3, den4, den5, den6, den7, mes01, mes02, mes03, mes04, mes05, mes06, mes07, mes08, mes09, mes10, mes11, mes12, casod, casdo, datumod, datumdo, dat_cas_zm, autor, vs_typy_kr, vs_org, idriadok_master)						
								SELECT idriadok, c_kasy, meno, aktivna, zmazana, den1, den2, den3, den4, den5, den6, den7, mes01, mes02, mes03, mes04, mes05, mes06, mes07, mes08, mes09, mes10, mes11, mes12, casod, casdo, datumod, datumdo, dat_cas_zm, autor, vs_typy_kr, vs_org, idriadok as idriadok_master FROM								
									dblink('connstrx','SELECT idriadok, c_kasy, meno, aktivna, zmazana, den1, den2, den3, den4, den5, den6, den7, mes01, mes02, mes03, mes04, mes05, mes06, mes07, mes08, mes09, mes10, mes11, mes12, casod, casdo, datumod, datumdo, dat_cas_zm, autor, vs_typy_kr, vs_org FROM kredit.hk_sj_hlav ORDER BY idriadok') 																		
									as remzmeny(idriadok INTEGER, c_kasy INTEGER, meno CHARACTER(30), aktivna SMALLINT, zmazana SMALLINT, den1 SMALLINT, den2 SMALLINT, den3 SMALLINT, den4 SMALLINT, den5 SMALLINT, 
									den6 SMALLINT, den7 SMALLINT, mes01 SMALLINT, mes02 SMALLINT, mes03 SMALLINT, mes04 SMALLINT, mes05 SMALLINT, mes06 SMALLINT, mes07 SMALLINT, mes08 SMALLINT, mes09 SMALLINT, mes10 SMALLINT,
									mes11 SMALLINT, mes12 SMALLINT, casod CHARACTER(8), casdo CHARACTER(8), datumod DATE, datumdo DATE, dat_cas_zm  TIMESTAMP WITHOUT TIME ZONE, autor CHARACTER(3), vs_typy_kr SMALLINT, vs_org SMALLINT);
							ALTER TABLE kredit.hk_sj_hlav ENABLE TRIGGER ALL;
							SELECT MAX(idriadok) into maxid FROM kredit.hk_sj_hlav;
							SELECT nextval('kredit.hk_sj_hlav_idriadok_seq') into maxid2;
							IF maxid IS NOT NULL THEN
								IF maxid+1<>maxid2 THEN
									PERFORM setval('kredit.hk_sj_hlav_idriadok_seq', maxid, true);
								END IF;
							ELSE
								IF maxid2<>1 THEN
									PERFORM setval('kredit.hk_sj_hlav_idriadok_seq', 1, true);
								END IF;
							END IF;
						ELSE
					END CASE;
				END IF;
			END LOOP;
			CLOSE zoznamtabuliek;
			-- L.L. Opravene nastavovanie max. V selectoch zo sync_idriadok a sync_hkredobr zmenene idriadok na idr a pri update zmena where idriadok=mojeid na idriadok=mojmaster
			SELECT idriadok into maxid FROM dblink('connstrx','SELECT max(idriadok) as idriadok FROM food600.sync_karty WHERE operacia=''I'' ') as remzmeny(idriadok BIGINT) ;
			IF maxid IS NULL THEN
				maxid:=0;
			END IF;
			RAISE NOTICE 'id_remote_insert_karty:%',maxid;
			UPDATE food600.sync_set SET id_local_update_karty=0, id_local_insert_karty=0, id_local_update_skupiny=0, id_local_insert_skupiny=0,id_local_update=0, id_local_insert=0, id_local_delete=0, id_local_insert_hkredobr=0, id_local_update_hkredobr=0, id_local_delete_hkredobr=0, id_remote_insert_karty=maxid where idriadok=mojmaster;
			SELECT idriadok into maxid FROM dblink('connstrx','SELECT max(idriadok) as idriadok FROM food600.sync_karty WHERE operacia=''U'' ') as remzmeny(idriadok BIGINT) ;
			IF maxid IS NULL THEN
				maxid:=0;
			END IF;
			RAISE NOTICE 'id_remote_update_karty:%',maxid;
			UPDATE food600.sync_set SET id_remote_update_karty=maxid where idriadok=mojmaster;
			SELECT idriadok into maxid FROM dblink('connstrx','SELECT max(idriadok) as idriadok FROM food600.sync_skupiny WHERE operacia=''I'' ') as remzmeny(idriadok BIGINT) ;
			IF maxid IS NULL THEN
				maxid:=0;
			END IF;
			RAISE NOTICE 'id_remote_insert_skupiny:%',maxid;	
			UPDATE food600.sync_set SET id_remote_insert_skupiny=maxid where idriadok=mojmaster;
			SELECT idriadok into maxid FROM dblink('connstrx','SELECT max(idriadok) as idriadok FROM food600.sync_skupiny WHERE operacia=''U'' ') as remzmeny(idriadok BIGINT) ;
			IF maxid IS NULL THEN
				maxid:=0;
			END IF;
			RAISE NOTICE 'id_remote_update_skupiny:%',maxid;
			UPDATE food600.sync_set SET id_remote_update_skupiny=maxid where idriadok=mojmaster;
			SELECT idr into maxid FROM dblink('connstrx','SELECT max(idr) as idr FROM food600.sync_idriadok WHERE operacia=''I'' ') as remzmeny(idr BIGINT) ;
			IF maxid IS NULL THEN
				maxid:=0;
			END IF;
			RAISE NOTICE 'id_remote_insert:%',maxid;
			UPDATE food600.sync_set SET id_remote_insert=maxid where idriadok=mojmaster;
			SELECT idr into maxid FROM dblink('connstrx','SELECT max(idr) as idr FROM food600.sync_idriadok WHERE operacia=''U'' ') as remzmeny(idr BIGINT) ;
			IF maxid IS NULL THEN
				maxid:=0;
			END IF;
			RAISE NOTICE 'id_remote_update:%',maxid;
			UPDATE food600.sync_set SET id_remote_update=maxid where idriadok=mojmaster;
			SELECT idr into maxid FROM dblink('connstrx','SELECT max(idr) as idr FROM food600.sync_idriadok WHERE operacia=''D'' ') as remzmeny(idr BIGINT) ;
			IF maxid IS NULL THEN
				maxid:=0;
			END IF;
			RAISE NOTICE 'id_remote_delete:%',maxid;
			UPDATE food600.sync_set SET id_remote_delete=maxid where idriadok=mojmaster;
			-- L.L. (10.12.2021)
			SELECT idr into maxid FROM dblink('connstrx','SELECT max(idr) as idr FROM food600.sync_hkredobr WHERE operacia=''I'' ') as remzmeny(idr BIGINT) ;
			IF maxid IS NULL THEN
				maxid:=0;
			END IF;
			RAISE NOTICE 'id_remote_insert_hkredobr:%',maxid;
			UPDATE food600.sync_set SET id_remote_insert_hkredobr=maxid where idriadok=mojmaster;
			SELECT idr into maxid FROM dblink('connstrx','SELECT max(idr) as idr FROM food600.sync_hkredobr WHERE operacia=''U'' ') as remzmeny(idr BIGINT) ;
			IF maxid IS NULL THEN
				maxid:=0;
			END IF;		
			RAISE NOTICE 'id_remote_update_hkredobr:%',maxid;			
			UPDATE food600.sync_set SET id_remote_update_hkredobr=maxid where idriadok=mojmaster;
			SELECT idr into maxid FROM dblink('connstrx','SELECT max(idr) as idr FROM food600.sync_hkredobr WHERE operacia=''D'' ') as remzmeny(idr BIGINT) ;
			IF maxid IS NULL THEN
				maxid:=0;
			END IF;
			RAISE NOTICE 'id_remote_delete_hkredobr:%',maxid;	
			UPDATE food600.sync_set SET id_remote_delete_hkredobr=maxid where idriadok=mojmaster;			
			PERFORM dblink_disconnect('connstrx');
		END IF;
	ELSE
		ret:='Nenastavené parametre pripojenia k master serveru';
	END IF;
ELSE
	ret:='Nepriradený master server';
END IF;
RETURN ret;
END
$BODY$
;
