#[ ZACATEK SOUBORU ]#

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

#[ CREATE TABLE ZACATEK ]#
    c_stredisk integer NOT NULL DEFAULT 0,
    operace character(2) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    c_dokl integer NOT NULL DEFAULT 0,
    c_karty integer NOT NULL DEFAULT 0,
    mnozstvi numeric(20,10) NOT NULL DEFAULT (0),
    cena numeric(20,10) NOT NULL DEFAULT (0),
    cena_part numeric(20,10) NOT NULL DEFAULT (0),
    zustatek numeric(20,10) NOT NULL DEFAULT (0),
    cena_prum numeric(20,10) NOT NULL DEFAULT (0),
    dan numeric(5,3) NOT NULL DEFAULT 1,
    serial_no character(20) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    poradi integer NOT NULL DEFAULT 0,
    c_data smallint NOT NULL DEFAULT 1,
    idriadok SERIAL,
    spdan numeric(20,10) NOT NULL DEFAULT 0,
    spstupne numeric(20,10) NOT NULL DEFAULT 0,
    CONSTRAINT <TABLENAME>_<PRIMARYKEY> PRIMARY KEY (<PRIMARYKEY>)
#[ CREATE TABLE KONEC ]#

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

IF NOT EXISTS (SELECT indexname FROM pg_indexes WHERE schemaname='<SCHEMA>' and tablename='<TABLENAME>' and indexname='obraty_a_c_data') THEN
DROP INDEX IF EXISTS <SCHEMA>.obraty_a_c_data;
CREATE INDEX obraty_a_c_data
    ON <SCHEMA>.obraty_a USING btree
    (c_data ASC NULLS LAST)
    TABLESPACE pg_default;
END IF;

IF NOT EXISTS (SELECT indexname FROM pg_indexes WHERE schemaname='<SCHEMA>' and tablename='<TABLENAME>' and indexname='obraty_a_c_karty') THEN
DROP INDEX IF EXISTS <SCHEMA>.obraty_a_c_karty;
CREATE INDEX obraty_a_c_karty
    ON <SCHEMA>.obraty_a USING btree
    (c_karty ASC NULLS LAST)
    TABLESPACE pg_default;
END IF;

IF NOT EXISTS (SELECT indexname FROM pg_indexes WHERE schemaname='<SCHEMA>' and tablename='<TABLENAME>' and indexname='obraty_a_c_stredisk') THEN
DROP INDEX IF EXISTS <SCHEMA>.obraty_a_c_stredisk;
CREATE INDEX obraty_a_c_stredisk
    ON <SCHEMA>.obraty_a USING btree
    (c_stredisk ASC NULLS LAST)
    TABLESPACE pg_default;
END IF;

IF NOT EXISTS (SELECT indexname FROM pg_indexes WHERE schemaname='<SCHEMA>' and tablename='<TABLENAME>' and indexname='obraty_a_operace') THEN
DROP INDEX IF EXISTS <SCHEMA>.obraty_a_operace;
CREATE INDEX obraty_a_operace
    ON <SCHEMA>.obraty_a USING btree
    (operace COLLATE pg_catalog."default" ASC NULLS LAST)
    TABLESPACE pg_default;
END IF;

IF NOT EXISTS (SELECT indexname FROM pg_indexes WHERE schemaname='<SCHEMA>' and tablename='<TABLENAME>' and indexname='obraty_a_poradi') THEN
DROP INDEX IF EXISTS <SCHEMA>.obraty_a_poradi;
CREATE INDEX obraty_a_poradi
    ON <SCHEMA>.obraty_a USING btree
    (poradi ASC NULLS LAST)
    TABLESPACE pg_default;
END IF;

IF NOT EXISTS (SELECT indexname FROM pg_indexes WHERE schemaname='<SCHEMA>' and tablename='<TABLENAME>' and indexname='obraty_a_spolu') THEN
DROP INDEX IF EXISTS <SCHEMA>.obraty_a_spolu;
CREATE INDEX obraty_a_spolu ON <SCHEMA>.obraty_a USING btree
    (c_data ASC NULLS LAST, c_stredisk ASC NULLS LAST, c_dokl ASC NULLS LAST, c_karty ASC NULLS LAST, poradi ASC NULLS LAST)
    TABLESPACE pg_default;
END IF;

IF NOT EXISTS (SELECT indexname FROM pg_indexes WHERE schemaname='<SCHEMA>' and tablename='<TABLENAME>' and indexname='obraty_ac_dokl') THEN
DROP INDEX IF EXISTS <SCHEMA>.obraty_ac_dokl;
CREATE INDEX obraty_ac_dokl
    ON <SCHEMA>.obraty_a USING btree
    (c_dokl ASC NULLS LAST)
    TABLESPACE pg_default;
END IF;

IF NOT EXISTS (SELECT indexname FROM pg_indexes WHERE schemaname='<SCHEMA>' and tablename='<TABLENAME>' and indexname='obraty_aidriadok') THEN
DROP INDEX IF EXISTS <SCHEMA>.obraty_aidriadok;
CREATE INDEX obraty_aidriadok
    ON <SCHEMA>.obraty_a USING btree
    (idriadok ASC NULLS LAST)
    TABLESPACE pg_default;
END IF;

END IF;

#[ KONEC SOUBORU ]#