-- 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='crdzamky_asdf') THEN

CREATE TABLE food600.crdzamky_asdf 
(
    chipcode character(25) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    platichip character(25) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    kod_karty character(12) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    cis_kred character(16) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    c_hlad character(1) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    c_karty integer NOT NULL DEFAULT 0,
    naz_sluzby character(30) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    povolzony character(10) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    omezzony character(10) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    cenazajedn numeric(6,0) NOT NULL DEFAULT 0,
    cas_zadani character(19) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    cas_vstup character(19) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    cas_odchod character(19) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    minutbezpl numeric(2,0) NOT NULL DEFAULT 0,
    minutzapl numeric(5,0) NOT NULL DEFAULT 0,
    can_in numeric(1,0) NOT NULL DEFAULT 0,
    can_out numeric(1,0) NOT NULL DEFAULT 0,
    can_always numeric(1,0) NOT NULL DEFAULT 0,
    n_pokin numeric(2,0) NOT NULL DEFAULT 0,
    n_pokout numeric(2,0) NOT NULL DEFAULT 0,
    last_t_in character(19) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    last_t_out character(19) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    tinpodzony character(19) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    toutpodzon character(19) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    c_kartynew integer NOT NULL DEFAULT 0,
    naz_sluzn character(30) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::bpchar,
    idklienta integer NOT NULL DEFAULT 0,
    maxcena numeric(6,0) NOT NULL DEFAULT 0,
    idriadok serial NOT NULL ,
    CONSTRAINT crdzamky_asdf_idriadok PRIMARY KEY (idriadok)
)
WITH (
    OIDS = FALSE
)
TABLESPACE pg_default;

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