#[ ZACATEK SOUBORU ]#

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

#[ CREATE TABLE ZACATEK ]#
    u_cis character(7) COLLATE pg_catalog."default",
    txt character(35) COLLATE pg_catalog."default",
    jmeno character(35) COLLATE pg_catalog."default",
    adresa1 character(35) COLLATE pg_catalog."default",
    adresa2 character(35) COLLATE pg_catalog."default",
    adresa3 character(35) COLLATE pg_catalog."default",
    schvalil character(35) COLLATE pg_catalog."default",
    akce character(35) COLLATE pg_catalog."default",
    dic character(15) COLLATE pg_catalog."default",
    cislo character(15) COLLATE pg_catalog."default",
    hucet character(15) COLLATE pg_catalog."default",
    hpokoj character(6) COLLATE pg_catalog."default",
    hjmeno character(40) COLLATE pg_catalog."default",
    hporad character(2) COLLATE pg_catalog."default",
    hpref character(15) COLLATE pg_catalog."default",
    id_kas character(2) COLLATE pg_catalog."default",
    uzaverka character(17) COLLATE pg_catalog."default",
    hid character(12) COLLATE pg_catalog."default",
    icdph character(20) COLLATE pg_catalog."default",
    ico character(15) COLLATE pg_catalog."default",
    poradi integer,
    c_data smallint NOT NULL DEFAULT 1,
    idriadok SERIAL,
    CONSTRAINT <TABLENAME>_<PRIMARYKEY> PRIMARY KEY (<PRIMARYKEY>)
#[ CREATE TABLE KONEC ]#

#[ IF EXIST ZACATEK ]#
#[ PRIMARYKEY ]#
	IF EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='sk_txt' and column_name='hpokoj') THEN
		ALTER TABLE <SCHEMA>.sk_txt   ALTER COLUMN hpokoj TYPE character(8);
	END IF;

	IF EXISTS ( SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='sk_txt' and column_name='hjmeno'  and character_maximum_length < 40 ) THEN
		ALTER TABLE <SCHEMA>.sk_txt  ALTER COLUMN hjmeno TYPE character(40) USING left(hjmeno, 40) ;
	END IF;

	IF EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='sk_txt' and column_name='poradi') THEN
		ALTER TABLE <SCHEMA>.sk_txt   ALTER COLUMN poradi TYPE integer;
	END IF;

END IF;

#[ KONEC SOUBORU ]#