Re: Why does this not work? - Mailing list pgsql-general

From Stephan Szabo
Subject Re: Why does this not work?
Date
Msg-id 20020411105253.H35227-100000@megazone23.bigpanda.com
Whole thread Raw
In response to Why does this not work?  ("Johann Zuschlag" <zuschlag@online.de>)
Responses Re: Why does this not work?  ("Johann Zuschlag" <zuschlag@online.de>)
List pgsql-general
On Thu, 11 Apr 2002, Johann Zuschlag wrote:

> -- Table: test
> CREATE TABLE "test" (
>   "test1" varchar(10)
> ) WITH OIDS;
>
> -- Function: laenge()
> CREATE FUNCTION "laenge"() RETURNS "opaque" AS '
> begin
> if length(new.test1) > 10 then
>         new.test1 = substr(new.test1,1,9);
> end if;
> return new;
> end
> ' LANGUAGE 'plpgsql';
>
> -- Trigger: laenge_trig ON test
> CREATE TRIGGER "laenge_trig" BEFORE INSERT OR UPDATE ON "test" FOR
> EACH ROW EXECUTE PROCEDURE laenge();
>
> insert into test (test1) values  ('0123456789012');
>
> value too long for type character varying(10)

The value is being coerced into the type before your trigger
runs to be put into the values you're testing and it fails
at that point.



pgsql-general by date:

Previous
From: Oleg Bartunov
Date:
Subject: Re: Critical performance problems on large databases
Next
From: Gunther Schadow
Date:
Subject: Re: Critical performance problems on large databases