From: | Cedar Cox <cedarc(at)visionforisrael(dot)com> |
---|---|
To: | Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com> |
Cc: | Najm Hashmi <najm(at)mondo-live(dot)com>, pgsql <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: is it me or trigger side effects |
Date: | 2001-03-26 20:42:57 |
Message-ID: | Pine.LNX.4.21.0103262242100.3439-100000@nanu.visionforisrael.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Mon, 26 Mar 2001, Stephan Szabo wrote:
>
> > 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).
You probably want to handle UPDATEs as well.. make sure you plan for this
too.
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2001-03-26 21:09:14 | Re: Function Vanished |
Previous Message | Cedar Cox | 2001-03-26 20:38:37 | Re: Help |