Re: value too long error

From: Richard Huxton <dev(at)archonet(dot)com>
To: "Rajat Katyal" <rajatk(at)intelesoftech(dot)com>, "Uwe C(dot) Schroeder" <uwe(at)oss4u(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: value too long error
Date: 2004-02-28 15:03:54
Message-ID: 200402281503.54915.dev@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Saturday 28 February 2004 08:36, Rajat Katyal wrote:
> Ya, through application we can provide field input validation but iam
> working on the tool which transfers the data from some specifed database to
> another. Here user itself wants if value is too long for the target column
> then truncates the text and insert into the target field. It was there in
> postgres version 7.2 but not in postgres 7.3.
>
> At database level how can we provide a check if text size is greater than
> that of field size then truncate it?

Unfortunately, you can't do this with a BEFORE INSERT trigger, since the
type-checking (which includes length) is done before the trigger will get
called.

You could however:
1. Have a duplicate table, except with unlimited varchar fields and import
into that. Once the batch is in, move it to the destination table with the
relevant substr()
2. You *should* be able to do the same, but with a before trigger that trims,
then inserts to the destination table before returning NULL.
3. You might even be able to use a view with a rule that instead trims the
relevant text fields. Not sure about this one.

--
Richard Huxton
Archonet Ltd

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2004-02-28 15:52:08 Re: value too long error
Previous Message Geoffrey Kinnel 2004-02-28 13:54:08 Where are the backend/commands?