-- add column phoneline.dnd
BEGIN;

CREATE or REPLACE FUNCTION  add_phoneline_dnd() RETURNS integer AS '
  BEGIN
    IF SPLIT_PART(VERSION(), '' '', 2) = ''7.4.7''
    THEN
      alter table phoneline add column dnd varchar(3);
      update phoneline set dnd = ''yes'' where dnd is null;
      alter table phoneline alter phoneline_dnd set default ''no'';
      alter table phoneline alter phoneline_dnd set not null;
    ELSE
      alter table phoneline add column dnd varchar(3) not null default ''no'';
    END IF;
    RETURN 0;
  END;
' LANGUAGE plpgsql;

select add_phoneline_dnd();

DROP FUNCTION add_phoneline_dnd();
COMMIT;

