X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id D3685D1DA65 for ; Fri, 6 Feb 2004 21:23:43 +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 08129-03 for ; Fri, 6 Feb 2004 17:23:41 -0400 (AST) Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) by svr1.postgresql.org (Postfix) with ESMTP id A35F5D1D9F2 for ; Fri, 6 Feb 2004 17:23:39 -0400 (AST) Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) by mail1.ihs.com (8.12.10/8.12.10) with ESMTP id i16LMIB3010591; Fri, 6 Feb 2004 14:22:18 -0700 (MST) Date: Fri, 6 Feb 2004 14:17:58 -0700 (MST) From: "scott.marlowe" To: Cc: Subject: Re: Problem with too short column In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-IHS-MailScanner: Found to be clean X-IHS-MailScanner-SpamCheck: X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200402/100 X-Sequence-Number: 12274 On Wed, 4 Feb 2004 Thomas.AUBRY@limagrain.com wrote: > Hi, > > I actually try to insert varchar which length is higher than 32 in a column > which type is varchar(32). I can't change the type of the column, and I > want to trunc the data. I know it's possible ! I have seen this ! > > Example : "j'aime les saucisses avec du beurre dedans" will be "j'aime les > saucisses avec du beu". For the moment it produces a SQL Error ! > > Is it an option in the config files ? No, it's your job to truncate it. You could use substring in your insert statement like this: insert into tablename (fieldname) values (substring('inputdatathatstoolonghere',0 for x); where x is the length you want it chopped off at. Further, you could create an insert (i.e. before) trigger to do the same thing. Note that the SQL spec is very clear, truncating automatically is an error, and if you want things truncated, it's not the databases job to do it by any kind of "default" setting. Luckily, it's pretty easy to do it either "by hand" in SQL with substring, or by trigger. > I'm using Postgresql 7.2.2. Upgrade. There are bugs in the early 7.2 series you don't want to have to deal with. I'd recommend going to 7.4.1 if you can, but if not, at least upgrade to the latest version of 7.2. As long as you compile it the same as your earlier 7.2 install, it's an in place (i.e. no dump restore required) upgrade.