Problem with triggers

From: Sid <sid(dot)the(dot)technician(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Problem with triggers
Date: 2010-06-15 21:01:29
Message-ID: AANLkTik6-sNYpAbiaZtipPJkqxbOrfVAZb1EFk0CNHYw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

I am writing trigger function for validating values inserted into table. The
goal is to print user friendly messages when inserted value is wrong.
When I check for null values everything works as expected:
Inside trigger I have lines:
if (new.tvalue is null) then
RAISE EXCEPTION 'error message';
end if;
This one works ok.

But when I try to do something like that:

if length(new.tvalue) > 20 then
RAISE EXCEPTION 'error message - too long';
end if;

then I get just information from database that given field value is to long
(of course only when I try insert too long value).

In fact even if I put RAISE EXCEPTION as first line inside trigger it does
not work.
All I get is ERROR: value to long......

Trigger declaration looks as follows:
CREATE TRIGGER bir_validate
BEFORE INSERT OR UPDATE
ON portal.documentation
FOR EACH ROW
EXECUTE PROCEDURE portal.dynamic_trigger_validate();

Postgres 8.4.4 on Windows 7 32bit

My question is: why do I get information about too long value before trigger
fires?
Can I change this behavior?

--
Best regards
Sid

Responses

Browse pgsql-general by date

  From Date Subject
Next Message greigwise 2010-06-15 21:25:14 Re: GSS Authentication
Previous Message Dave Page 2010-06-15 20:35:47 Re: Problem serving one-click installer to Syria