Skip site navigation (1) Skip section navigation (2)

Re: Field with character varying (255)

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: "Christopher A(dot) Goodfellow" <cgoodfellow(at)tealuxe(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Field with character varying (255)
Date: 2004-04-27 17:38:40
Message-ID: 20040427173840.GA1712@wolff.to (view raw or flat)
Thread:
Lists: pgsql-novice
On Mon, Apr 26, 2004 at 12:48:43 -0400,
  "Christopher A. Goodfellow" <cgoodfellow(at)tealuxe(dot)com> wrote:
> I have a table with a field set to character varying (255).  When an insert
> is executed with a value for this field greater than 255 characters, an
> error is generated rather than the input being truncated as stated in the
> postgresql docs.

Are you using an explicit cast? An implicit cast will return an error,
but an explicit cast should silently truncate the string.
This example is in a 7.4.2+ database:
bruno=> create table test3 (col varchar(3));
CREATE TABLE
bruno=> insert into test3 values ('1234');
ERROR:  value too long for type character varying(3)
bruno=> insert into test3 values ('1234'::varchar(3));
INSERT 1242541 1
bruno=> select * from test3;
 col
-----
 123
(1 row)

In response to

pgsql-novice by date

Next:From: Robert MorganDate: 2004-04-27 22:53:58
Subject: Validation rules
Previous:From: Stephan SzaboDate: 2004-04-26 18:58:55
Subject: Re: access information_schema

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group