before trigger doesn't, on insert of too long data

From: Thomas Erskine <thomas(dot)erskine(at)sympatico(dot)ca>
To: pgsql-bugs(at)postgresql(dot)org
Cc: Anil Nair <anil(at)talentmap(dot)com>
Subject: before trigger doesn't, on insert of too long data
Date: 2003-11-08 03:10:12
Message-ID: 5.2.1.1.0.20031107220635.00b0d508@pop1.sympatico.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

============================================================================
POSTGRESQL BUG REPORT TEMPLATE
============================================================================

Your name : Thomas Erskine
Your email address : thomaserskine(at)yahoo(dot)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(dot)erskine(at)sympatico(dot)ca> +1.613.591.8490

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2003-11-08 04:09:55 Re: pg_dump function dumped after required for table definition
Previous Message bvctravel 2003-11-08 02:57:12 postgresql-7.4RC1 - unrecognized privilege type when selecting from information_schema.tables