Re: trigger: NEW/OLD-error or nothing happens

From: Jan Wieck <JanWieck(at)Yahoo(dot)com>
To: Knut Suebert <knut(dot)suebert(at)web(dot)de>
Cc: PostgreSQL GENERAL <pgsql-general(at)PostgreSQL(dot)org>
Subject: Re: trigger: NEW/OLD-error or nothing happens
Date: 2001-07-09 13:52:12
Message-ID: 200107091352.f69DqCp07285@jupiter.us.greatbridge.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Knut Suebert wrote:
> Joe Conway schrieb:
>
> > OLD does not make sense on an insert because there is no "OLD" data for a
> > brand new row. Similarly, there is no "NEW" data during a delete. See
> > http://www.postgresql.org/idocs/index.php?plpgsql-trigger.html
>
> Makes sense, thanks. And at the bottom of that page is a nice hint
> regarding the trigger BEFORE/AFTER insert.
>
> So I changed to BEFORE -- but still nothing happens
>
> An exception for debugging:
>
> create function nac_viceversa() returns opaque as'
> declare
> x int4;
> begin
> x := nacmin(NEW.sport,NEW.dport)
> NEW.minport := x;
> NEW.maxport := nacmax(NEW.sport,NEW.dport);
> raise exception ''%'',x;
> return NEW;
> end;
> 'language 'plpgsql';
>
> create trigger nac_update before insert or update on traf
> for each row execute procedure nac_viceversa();
>
> the calculation works...
>
> ERROR: 110
> ERROR: 110
> ERROR: 110
>
> ... but is not written into the row -- even after removing the exception ;-)
>
> id | ... | device | minport | maxport
> 12151 | ... | eth0 | |
> 12152 | ... | eth0 | |
>
> Am I stupid?

You can use RAISE NOTICE to have *debugging* without rolling
back the transaction. Maybe it'd help to add more RAISE's to
see the values of NEW.sport and NEW.dport as well?

And you don't need the eXtra variable. NEW.attrib should work
well in the RAISE.

Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck(at)Yahoo(dot)com #

_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Fabrizio Mazzoni 2001-07-09 14:04:05 Transactions in rules..
Previous Message Yasuo Ohgaki 2001-07-09 13:23:18 Re: [GENERAL] Re: QUERY - Including the new LDP PostgreSQL HOWTO in the main PostgreSQL distribution