before trigger doesn't, on insert of too long data - Mailing list pgsql-bugs

From Thomas Erskine
Subject before trigger doesn't, on insert of too long data
Date
Msg-id 5.2.1.1.0.20031107220635.00b0d508@pop1.sympatico.ca
Whole thread Raw
Responses Re: before trigger doesn't, on insert of too long data  (Neil Conway <neilc@samurai.com>)
List pgsql-bugs
============================================================================
                         POSTGRESQL BUG REPORT TEMPLATE
============================================================================


Your name               :       Thomas Erskine
Your email address      :       thomaserskine@yahoo.com


System Configuration
---------------------
   Architecture (example: Intel Pentium)         :Intel Pentium III

   Operating System (example: Linux 2.0.26 ELF)  :Linux 2.4.20 ELF

   PostgreSQL version (example: PostgreSQL-7.2.3):PostgreSQL-7.3.4-1PGDG

   Compiler used (example:  gcc 2.95.2)          : the RPM did it :-)


Please enter a FULL description of your problem:
------------------------------------------------
A before trigger doesn't always fire.  If a column being inserted into is
too small for the incoming data, psql complains:
     ERROR:  value too long for type ...
without giving the trigger procedure a chance to deal with it.


Please describe a way to repeat the problem.   Please try to provide a
concise reproducible example, if at all possible:
----------------------------------------------------------------------
------ cut here ------
CREATE TABLE test(
         id INTEGER,
         code CHARACTER(4)
);

CREATE FUNCTION test_func()
RETURNS TRIGGER
AS 'BEGIN
         IF LENGTH(new.code) > 4
         THEN    new.code = ''xxxx'';
         END IF;
         new.code = upper(new.code);
         RETURN new;
         END;'
LANGUAGE 'plpgsql';

CREATE TRIGGER test_trig
BEFORE INSERT
ON test
FOR EACH ROW
EXECUTE PROCEDURE test_func();

INSERT INTO test VALUES( 1, 'aaaa');

INSERT INTO test VALUES( 2, 'bbbbb');
------ cut here ------
The first INSERT works fine and the function is triggered.  The second
INSERT never triggers the function; it just complains.

If you know how this problem might be fixed, list the solution below:
---------------------------------------------------------------------




Thomas Erskine <thomas.erskine@sympatico.ca> +1.613.591.8490

pgsql-bugs by date:

Previous
From: "Oliver Siegmar"
Date:
Subject: psql client 7.4RC1 completion bug
Next
From:
Date:
Subject: postgresql-7.4RC1 - unrecognized privilege type when selecting from information_schema.tables