Thread: Trigger Error!

Trigger Error!

From
jreniz
Date:
Hi!

I've postgresql 6.5.3 system and 50 tables, but i need to run  this
trigger: (the comments are in spanish :-) )

create function gen_req() returns opaque as '
    declare
     cantdisp int4;
     suma int4;
     cantprodsol int4;
     codereq int4;

   begin
    if int4ne(new.candisproter, old.candisproter) then
       select candisproter into cantdisp from proter
       where codproter=new.codproter;

       if not found then
          raise exception ''No hay datos de productos'';
       end if;

       select sum(stomin) into suma from almproterpt
       where codproter=new.codproter;

       if not found then
          raise exception ''No hay datos de Stocks minimos'';
       end if;

       cantprodsol := old.candisproter - new.candisproter;

       if int4le((cantdis - cantprodsol), suma) then
        select codreq from requisicion
        where fecsalreq=current_date;
  if not found then
           --se inserta la requisicion;
           insert into requisicion(fecsalreq,codest)
values(current_date,1);
         end if;
        --se repite la query pero asignando el valor;
        select codreq into codereq from requisicion
        where fecsalreq=current_date;
        --procedemos a insertar el detalle;
        insert into detallereq(codreq,codpt,canpt)
        values(codereq,new.codproter,cantprodsol);
       end if;
     end if;
     return new;
   end;
' language 'plpgsql';

create trigger gen_req_tg before update on proter for each row execute
procedure gen_req();

Well, the trigger is created, the trigger should intercepts the update
event in table 'proter' and  when  I reduce the 'candisproter' field to
specied value then, the trigger is fired. But.........

It isn't work, when I run the update operation, then, I give this error:

'There is no operator '=$' for types 'int4' and 'int4' you will either
have to retype this query using and explicit cast, or you will have
to define the operator using CREATE OPERATOR'

I don't understand  what's the meaning af this message, the types are
incorrect??  WHAT'S WRONG?????

thankx!!!


Re: Trigger Error!

From
Richard Huxton
Date:
jreniz wrote:
>
> Hi!
>
> I've postgresql 6.5.3 system and 50 tables, but i need to run  this
> trigger: (the comments are in spanish :-) )

>        select sum(stomin) into suma from almproterpt
>        where codproter=new.codproter;

> 'There is no operator '=$' for types 'int4' and 'int4' you will either
> have to retype this query using and explicit cast, or you will have
> to define the operator using CREATE OPERATOR'

OK - in your other post you identified the problem as the above select
... into

I've tried to reproduce this in 7.1beta and can't (sorry don't have 6.5
to hand). On the other hand I can't spot any references to bug fixes in CHANGES.

You _must_ have and = operator for int4,int4 or you'd have noticed - you
can try a cast on the sum()

select sum(stomin)::int4 into suma ...

My guess is though that this is a bug in 6.5.x that has been fixed for
series 7 and I just couldn't spot it in the changes list.

- Richard Huxton