DO
$$
BEGIN
IF EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and udt_name LIKE 'int_' and table_name='<TABLENAME>' and column_name='poradi') THEN

	IF EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='<TABLENAME>' and column_name='poradi' and udt_name<>'int4') THEN
		ALTER TABLE <SCHEMA>.<TABLENAME> ALTER COLUMN poradi TYPE int4 USING poradi::int4;
	END IF;

	IF EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='<TABLENAME>' and column_name='poradi' and (lower(btrim(column_default))<>'0' or column_default is null) ) THEN
		ALTER TABLE <SCHEMA>.<TABLENAME> ALTER COLUMN poradi SET DEFAULT 0 ;
	END IF;

	IF EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='<TABLENAME>' and column_name='poradi' and lower(btrim(is_nullable))<>'no') THEN
                UPDATE      <SCHEMA>.<TABLENAME> SET poradi = 0 WHERE poradi IS NULL;
		ALTER TABLE <SCHEMA>.<TABLENAME> ALTER COLUMN poradi SET NOT NULL  ;
	END IF;

END IF;

IF EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and udt_name LIKE 'int_' and table_name='<TABLENAME>' and column_name='poradie') THEN

	IF EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='<TABLENAME>' and column_name='poradie' and udt_name<>'int4') THEN
		ALTER TABLE <SCHEMA>.<TABLENAME> ALTER COLUMN poradie TYPE int4 USING poradie::int4;
	END IF;

	IF EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='<TABLENAME>' and column_name='poradie' and (lower(btrim(column_default))<>'0' or column_default is null) ) THEN
		ALTER TABLE <SCHEMA>.<TABLENAME> ALTER COLUMN poradie SET DEFAULT 0 ;
	END IF;

	IF EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='<TABLENAME>' and column_name='poradie' and lower(btrim(is_nullable))<>'no') THEN
                UPDATE      <SCHEMA>.<TABLENAME> SET poradie = 0 WHERE poradie IS NULL;
		ALTER TABLE <SCHEMA>.<TABLENAME> ALTER COLUMN poradie SET NOT NULL  ;
	END IF;

END IF;
END
$$
