Re: is it me or trigger side effects - Mailing list pgsql-sql

From Stephan Szabo
Subject Re: is it me or trigger side effects
Date
Msg-id Pine.BSF.4.21.0103260907230.59546-100000@megazone23.bigpanda.com
Whole thread Raw
In response to is it me or trigger side effects  (Najm Hashmi <najm@mondo-live.com>)
Responses Re: is it me or trigger side effects
List pgsql-sql
> create function updateCat() returns opaque as '
> declare
>     rec     record;
>     rename new to cat;
>     rename old to ct;
>     maxlen integer;
> 
> begin
>      if tg_op = ''INSERT''  and cat.category is null then
>           raise exception ''You are missing entry for category field'';
> 
>      else
>           if cat.display then
>                maxlen:= addCount(cat.category);
>                return cat;
>           else
>                return cat;
>           end if;
>      end if;
>      if tg_op = ''DELETE''then
>           maxlen:= delCount(ct.category);
>           return ct;
>      end if;
> 
> end;
> ' language 'plpgsql';

I think you want your if blocks to be more like:
if tg_op = ''INSERT''if cat.category is null (raise exception)else (do insert stuff)end if
end if
if tg_op = ''DELETE''(do delete stuff)
end if

I think you're currently going to get into the 
insert stuff on both inserts where it isn't
null and deletes (since in both cases the
and will be false).




pgsql-sql by date:

Previous
From: Jeff Eckermann
Date:
Subject: RE: Still don't know how to build this string ?
Next
From: "A. Van Hook"
Date:
Subject: paging