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

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

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

END IF;
END
$$
