#[ ZACATEK SOUBORU ]#

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

#[ CREATE TABLE ZACATEK ]#
    id_kas character(2) COLLATE pg_catalog."default",
    u_cis character(7) COLLATE pg_catalog."default",
    uzaverka character(17) COLLATE pg_catalog."default",
    fucis integer,
    fuciarkod character(20) COLLATE pg_catalog."default",
    fuzcislo integer,
    fuzdate date,
    idriadok SERIAL,
    okp character(45) COLLATE pg_catalog."default",
    uid character(50) COLLATE pg_catalog."default",

    c_data smallint NOT NULL DEFAULT 1,
    CONSTRAINT <TABLENAME>_<PRIMARYKEY> PRIMARY KEY (<PRIMARYKEY>)
#[ CREATE TABLE KONEC ]#

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

	IF NOT EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='<TABLENAME>' and column_name='okp') THEN
		ALTER TABLE <SCHEMA>.<TABLENAME>  ADD COLUMN okp CHARACTER(45)  NOT NULL  DEFAULT ''::BPCHAR;
	END IF;

	IF NOT EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='<TABLENAME>' and column_name='uid') THEN
		ALTER TABLE <SCHEMA>.<TABLENAME>  ADD  COLUMN uid CHARACTER(50)  DEFAULT ''::BPCHAR;
		ALTER TABLE <SCHEMA>.<TABLENAME> ALTER COLUMN uid TYPE character (50) COLLATE pg_catalog."default";
	END IF;


	IF EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='<TABLENAME>' and column_name='okp') THEN
		ALTER TABLE <SCHEMA>.<TABLENAME> ALTER COLUMN okp TYPE character (45) COLLATE pg_catalog."default";
		ALTER TABLE <SCHEMA>.<TABLENAME> ALTER COLUMN okp DROP NOT NULL;
	END IF;

	IF EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='<TABLENAME>' and column_name='okp' and column_default is not null) THEN
       	 ALTER TABLE IF EXISTS <SCHEMA>.<TABLENAME> ALTER COLUMN okp DROP DEFAULT;
	END IF;

	IF EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='<TABLENAME>' and column_name='uid' and column_default is not null) THEN
		ALTER TABLE IF EXISTS <SCHEMA>.<TABLENAME> ALTER COLUMN uid DROP DEFAULT;
	END IF;

	IF EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='<TABLENAME>' and column_name='okp' and is_nullable='NO') THEN
		ALTER TABLE IF EXISTS <SCHEMA>.<TABLENAME> ALTER COLUMN okp DROP NOT NULL;
	END IF;

	IF EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='<TABLENAME>' and column_name='uid' and is_nullable='NO') THEN
		ALTER TABLE IF EXISTS <SCHEMA>.<TABLENAME> ALTER COLUMN uid DROP NOT NULL;
	END IF;

END IF;
#[ KONEC SOUBORU ]#