CREATE OR REPLACE FUNCTION randomize_attlognums(p_attrelid regclass) RETURNS void AS $$
DECLARE
    v_att       RECORD;
    v_attlognum INT := 1;
BEGIN

    FOR v_att IN (SELECT attnum FROM pg_attribute WHERE (attrelid = p_attrelid) AND (attnum > 0) ORDER BY random()) LOOP
        UPDATE pg_attribute SET attlognum = v_attlognum WHERE (attrelid = p_attrelid) AND (attnum = v_att.attnum);
        v_attlognum := v_attlognum + 1;
    END LOOP;

END;
$$ LANGUAGE plpgsql;


CREATE OR REPLACE FUNCTION randomize_attphysnums(p_attrelid regclass) RETURNS void AS $$
DECLARE
    v_att       RECORD;
    v_attphysnums INT := 1;
BEGIN

    FOR v_att IN (SELECT attnum FROM pg_attribute WHERE (attrelid = p_attrelid) AND (attnum > 0) ORDER BY random()) LOOP
        UPDATE pg_attribute SET attphysnums = v_attphysnums WHERE (attrelid = p_attrelid) AND (attnum = v_att.attnum);
        v_attphysnums := v_attphysnums + 1;
    END LOOP;

END;
$$ LANGUAGE plpgsql;