
#[ ZACATEK SOUBORU ]#
DO
$$
BEGIN

#[ KONEC SOUBORU ]#
END
$$

#[ CREATE TABLE ZACATEK ]#
IF NOT EXISTS (SELECT table_name FROM information_schema.tables WHERE table_schema='<SCHEMA>' and table_name='<TABLENAME>') THEN 
CREATE TABLE IF NOT EXISTS <SCHEMA>.<TABLENAME>
(

#[ CREATE TABLE KONEC ]#
)
WITH (
    OIDS = FALSE
)
TABLESPACE pg_default;
  
END IF;


#[ IF EXIST ZACATEK ]#
IF EXISTS (SELECT table_name FROM information_schema.tables WHERE table_schema='<SCHEMA>' and table_name='<TABLENAME>') THEN 


#[ PRIMARYKEY ]#
	IF NOT EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='<TABLENAME>' and column_name='<PRIMARYKEY>') THEN
		ALTER TABLE <SCHEMA>.<TABLENAME> ADD COLUMN <PRIMARYKEY> serial ;
	END IF;

	IF NOT EXISTS (SELECT constraint_name FROM information_schema.table_constraints WHERE constraint_schema='<SCHEMA>' and table_name='<TABLENAME>' AND lower(constraint_type)='primary key') THEN

---		CREATE SEQUENCE IF NOT EXISTS <SCHEMA>.tmp_prim INCREMENT 1 START 1 MINVALUE 1;
---		UPDATE <SCHEMA>.<TABLENAME> set <PRIMARYKEY> = nextval('<SCHEMA>.tmp_prim');
---		DROP SEQUENCE <SCHEMA>.tmp_prim ;

		ALTER TABLE <SCHEMA>.<TABLENAME> ADD CONSTRAINT <TABLENAME>_<PRIMARYKEY> PRIMARY KEY (<PRIMARYKEY>) ;
	END IF;

#[ KONEC MAKER ]#
