From: Richard Huxton <dev@archonet.com>
To: Rajat Katyal <rajatk@intelesoftech.com>
To: Uwe C. Schroeder <uwe@oss4u.com>
Cc: pgsql-general@postgresql.org
Subject: Re: value too long error
Date: Sat, 28 Feb 2004 15:03:54 +0000
Message-ID: <200402281503.54915.dev@archonet.com> (raw)
In-Reply-To: <000a01c3fdd6$05d8aa60$2105a8c0@coffee>
References: <000a01c3fdc8$8adf1c70$2105a8c0@coffee>
<200402272316.45130.uwe@oss4u.com>
<000a01c3fdd6$05d8aa60$2105a8c0@coffee>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: dev@archonet.com, rajatk@intelesoftech.com, uwe@oss4u.com
Subject: Re: value too long error
In-Reply-To: <200402281503.54915.dev@archonet.com>
References: <000a01c3fdc8$8adf1c70$2105a8c0@coffee> <200402272316.45130.uwe@oss4u.com> <000a01c3fdd6$05d8aa60$2105a8c0@coffee> <200402281503.54915.dev@archonet.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox