-- Trigger Funktionen zu Rechten --
-- [
create function create_valid_rechte_mask()
    returns TRIGGER as '
        DECLARE
            err_msg text;
            new_len int4;
            old_len int4;
            dummy RECORD;
            sel text;
        BEGIN
            IF TG_OP <> ''UPDATE'' AND TG_OP <> ''INSERT'' THEN
                err_msg := TG_NAME || '': called for wrong action '' || TG_OP;
                RAISE EXCEPTION ''%'', err_msg;
            END IF;

            new_len := bit_length(NEW.maske);
            old_len := fibu.konto_typ_min_len();

            IF new_len < old_len THEN
                NEW.maske := bit_set_len(NEW.maske, old_len);
            END IF; 

            IF old_len < new_len THEN
                EXECUTE ''update fibu.konten_typen set konto_typ=konto_typ'' ||
                        ''::BIT('' || new_len || '')>>'' || new_len-old_len;
            END IF;

            RETURN NEW;
        END;
    ' language 'plpgsql';

-- create function on_ref_count_null_del_konto()
