Re: Why does this not work?

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Johann Zuschlag <zuschlag(at)online(dot)de>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Why does this not work?
Date: 2002-04-11 17:54:42
Message-ID: 20020411105253.H35227-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2002-04-11 17:56:16 Re: Critical performance problems on large databases
Previous Message Fran Fabrizio 2002-04-11 17:51:43 Re: where to find info about data types?