X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 21C8FD1D249 for ; Sat, 28 Feb 2004 15:04:01 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 43340-04 for ; Sat, 28 Feb 2004 11:04:02 -0400 (AST) Received: from anchor-post-31.mail.demon.net (anchor-post-31.mail.demon.net [194.217.242.89]) by svr1.postgresql.org (Postfix) with ESMTP id 2C120D1BB15 for ; Sat, 28 Feb 2004 11:03:57 -0400 (AST) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-31.mail.demon.net with esmtp (Exim 3.35 #1) id 1Ax60W-000EHg-0V; Sat, 28 Feb 2004 15:04:00 +0000 Received: by mainbox.archonet.com (Postfix, from userid 529) id 59F4A16F6A; Sat, 28 Feb 2004 15:03:59 +0000 (GMT) Received: from client17.archonet.com (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 2798916A79; Sat, 28 Feb 2004 15:03:56 +0000 (GMT) From: Richard Huxton To: "Rajat Katyal" , "Uwe C. Schroeder" Subject: Re: value too long error Date: Sat, 28 Feb 2004 15:03:54 +0000 User-Agent: KMail/1.5 Cc: References: <000a01c3fdc8$8adf1c70$2105a8c0@coffee> <200402272316.45130.uwe@oss4u.com> <000a01c3fdd6$05d8aa60$2105a8c0@coffee> In-Reply-To: <000a01c3fdd6$05d8aa60$2105a8c0@coffee> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200402281503.54915.dev@archonet.com> X-Bogosity: No, tests=bogofilter, spamicity=0.000000, version=0.15.3 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200402/1249 X-Sequence-Number: 57960 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