DO
$$
BEGIN
IF EXISTS (SELECT table_name FROM information_schema.tables WHERE table_schema='<SCHEMA>' and table_type='BASE TABLE' and table_name='<TABLENAME>') THEN 
	IF EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='<TABLENAME>' and column_name='c_data') THEN

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

		IF EXISTS (SELECT column_name FROM information_schema.columns WHERE table_schema='<SCHEMA>' and table_name='<TABLENAME>' and column_name='c_data' and lower(btrim(is_nullable))<>'no') THEN
        	        UPDATE      <SCHEMA>.<TABLENAME> SET c_data = 1 WHERE c_data IS NULL;
			ALTER TABLE <SCHEMA>.<TABLENAME> ALTER COLUMN c_data 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_data' and (lower(btrim(column_default))<>'1' or column_default is null) ) THEN
			ALTER TABLE <SCHEMA>.<TABLENAME> ALTER COLUMN c_data SET DEFAULT 1 ;
		END IF;

	ELSE
		ALTER TABLE <SCHEMA>.<TABLENAME> ADD COLUMN c_data smallint NOT NULL DEFAULT 1 ;

	END IF;
 END IF;
END
$$
