BEGIN;

-- queue.table

-- First change existing table entries.
CREATE or REPLACE FUNCTION tmp_update_queue_maxlen() RETURNS INTEGER AS '
  DECLARE
    _dflt int;
  BEGIN
    SELECT INTO _dflt column_default FROM information_schema.columns WHERE table_name = ''queue'' AND column_name = ''maxlen'';
    IF _dflt = 0 THEN
      UPDATE queue SET maxlen = ''9999'' WHERE maxlen = ''0'';
    ELSE
      RAISE INFO ''Default maxlen is %'', _dflt;
    END IF;
    RETURN ''0'';
  END;
' LANGUAGE plpgsql;

SELECT tmp_update_queue_maxlen();

DROP FUNCTION tmp_update_queue_maxlen();

-- Then change the default value.
ALTER TABLE queue ALTER COLUMN maxlen SET DEFAULT '9999';

-- queuelog.table

-- First change existing table entries.
CREATE or REPLACE FUNCTION tmp_update_queuelog_maxcallers() RETURNS INTEGER AS '
  DECLARE
    _dflt int;
  BEGIN
    SELECT INTO _dflt column_default FROM information_schema.columns WHERE table_name = ''queuelog'' AND column_name = ''maxcallers'';
    IF _dflt = 0 THEN
      UPDATE queuelog SET maxcallers = ''9999'' WHERE maxcallers = ''0'';
    ELSE
      RAISE INFO ''Default maxcallers is %'', _dflt;
    END IF;
    RETURN ''0'';
  END;
' LANGUAGE plpgsql;

SELECT tmp_update_queuelog_maxcallers();

DROP FUNCTION tmp_update_queuelog_maxcallers();

-- Then change the default value.
ALTER TABLE queuelog ALTER COLUMN maxcallers SET DEFAULT '9999';

COMMIT;
