Trigger does not work as expected

From: "Johann Zuschlag" <zuschlag(at)online(dot)de>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Trigger does not work as expected
Date: 2002-03-27 13:21:10
Message-ID: E16qDMX-00052a-00@mrvdom03.kundenserver.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

since 7.2 (I'm using 7.2.1) there is not anymore
an implicit truncation when I try to insert,update
a VARCHAR. (msg: value to long for type character
varying (XX))
Even though I could change these columns to TEXT,
there are reasons I don't want to.

So I tried the following with a TRIGGER:

(TABLE kunde, COLUMN kundennumm = varchar(20))

create or replace function laenge() returns opaque as '
begin
if length(new.kundennumm) > 6 then
raise exception '' Error! To long.'';
new.kundennumm = substr(new.kundennumm,1,6);
end if;
return new;
end
' Language 'plpgsql'

create trigger laenge_trig before insert or update on kunde
for each row execute procedure laenge();

If I try to insert a value with 21 characters:

insert into kunde (kundennumm) values ('123456789012345678901');

I get: value to long for type character varying (20)

I don't even see the exception. So the parser seems to checks the length
before the trigger? Did I misunderstand something?

Could somebody give me hint?

regards

Johann Zuschlag
zuschlag(at)online(dot)de

Browse pgsql-general by date

  From Date Subject
Next Message Johann Zuschlag 2002-03-27 13:36:32 Re: Trigger does not work as expected
Previous Message PGMailList 2002-03-27 12:37:44 Re: command to Describe RULE