My trigger does not work

1

I have a problem with a trigger in postgresql, its function is to perform an update on a field of the same table in which I insert, because that field can have different values, it is understood that this field is a nomenclature of a document, it can be inscription, license, x, for this I use some sequences for each type of document.

It turns out that the trigger does not update the field, I use django and postgresql.

here I leave the code

set search_path=funciones_vistas;
create or replace function nro_tramite() returns trigger as $$
declare
siglas_tramite varchar;
begin
    siglas_tramite := siglas from tools.tipo_tramite where id = new.tipo_tramite_id;
    if siglas_tramite = 'IU' then
        new.nro_tramite := 'SDLC-'||siglas_tramite||'-'||lpad(nextval('"funciones_vistas".inscripcion')::text,5,'0');
        return new;
    elsif siglas_tramite = 'LCA' then
        new.nro_tramite := 'SDLC-'||siglas_tramite||'-'||lpad(nextval('"funciones_vistas".licencia_ca')::text,5,'0');
        return new;
    elsif siglas_tramite = 'LCO' then
        new.nro_tramite := 'SDLC-'||siglas_tramite||'-'||lpad(nextval('"funciones_vistas".licencia_co')::text,5,'0');
        return new;
    elsif siglas_tramite = 'LTM' then
        new.nro_tramite := 'SDLC-'||siglas_tramite||'-'||lpad(nextval('"funciones_vistas".licencia_tlm')::text,5,'0');
        return new;
    elsif siglas_tramite = 'LOP' then
        new.nro_tramite := 'SDLC-'||siglas_tramite||'-'||lpad(nextval('"funciones_vistas".licencia_op')::text,5,'0');
        return new;
    elsif siglas_tramite = 'REN' then
        new.nro_tramite := 'SDLC-'||siglas_tramite||'-'||lpad(nextval('"funciones_vistas".renovacion')::text,5,'0');
        return new;
    elsif siglas_tramite = 'APT' then
        new.nro_tramite := 'SDLC-'||siglas_tramite||'-'||lpad(nextval('"funciones_vistas".aportes')::text,5,'0');
        return new;
    end if;
end;
$$
language 'plpgsql';

create trigger nro_tramite after insert on recaudacion.tramite for each row execute procedure nro_tramite();
    
asked by Argenis Msy 29.08.2018 в 07:19
source

0 answers