-- Podle Milana, konstrukce create table if not exists nefunguje na starsich Postgresech

DO
$$
BEGIN
IF NOT EXISTS (SELECT table_name FROM information_schema.tables WHERE table_schema='food600' and table_name='kuchyn_asdf') THEN

CREATE TABLE food600.kuchyn_asdf 
(
    c_bonu integer NOT NULL DEFAULT 0,
    prn_no character(2) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    stul numeric(6,1) NOT NULL DEFAULT 0,
    pgm_id character(2) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    kolik numeric(6,1) NOT NULL DEFAULT 0,
    delitel numeric(1,0) NOT NULL DEFAULT 1,
    nazev character(30) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    time character(5) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    cisnik character(15) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    poradi numeric(6,0) NOT NULL DEFAULT 0,
    zprava character(35) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    nk_vydeji numeric(1,0) NOT NULL DEFAULT 0,
    nvydano numeric(1,0) NOT NULL DEFAULT 0,
    vydano2 numeric(2,0) NOT NULL DEFAULT 0,
    barva numeric(1,0) NOT NULL DEFAULT 0,
    dtzprac character(19) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    typzaznamu numeric(4,0) NOT NULL DEFAULT 0,
    kdscolor character(8) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    kdsvideo character(8) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    cas_obj character(19) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    pc numeric(10,2) NOT NULL DEFAULT 0,
    tlokcas1 character(19) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    tlokcas2 character(19) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    nzaplaceno numeric(1,0) NOT NULL DEFAULT 0,
    idkuch integer NOT NULL DEFAULT 0,
    cdatum date NOT NULL DEFAULT '2020-10-01'::date,
    idriadok serial NOT NULL ,
    CONSTRAINT kuchyn_asdf_idriadok PRIMARY KEY (idriadok)
)
WITH (
    OIDS = FALSE
)
TABLESPACE pg_default;

ALTER TABLE food600.kuchyn_asdf
    OWNER to alto;
    
END IF;
END
$$
