pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: scott.marlowe <scott.marlowe@ihs.com>
To: Thomas.AUBRY@limagrain.com
Cc: pgsql-admin@postgresql.org
Subject: Re: Problem with too short column
Date: Fri, 6 Feb 2004 14:17:58 -0700 (MST)
Message-ID: <Pine.LNX.4.33.0402061412450.6661-100000@css120.ihs.com> (raw)
In-Reply-To: <OFE4BCE870.D91C8E9B-ONC1256E30.005ACE95@ftgin.net>

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.





view thread (4+ messages)  latest in thread

Message-ID: <Pine.LNX.4.33.0402061412450.6661-100000@css120.ihs.com>
Permalink:  ../Pine.LNX.4.33.0402061412450.6661-100000@css120.ihs.com/
Also on:    postgresql.org/message-id/Pine.LNX.4.33.0402061412450.6661-100000@css120.ihs.com

 · 

reply

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-admin@postgresql.org
  Cc: scott.marlowe@ihs.com, Thomas.AUBRY@limagrain.com
  Subject: Re: Problem with too short column
  In-Reply-To: <Pine.LNX.4.33.0402061412450.6661-100000@css120.ihs.com>
  References: <OFE4BCE870.D91C8E9B-ONC1256E30.005ACE95@ftgin.net> <Pine.LNX.4.33.0402061412450.6661-100000@css120.ihs.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