Re: value too long error - Mailing list pgsql-general

From Tom Lane
Subject Re: value too long error
Date
Msg-id 28033.1077983528@sss.pgh.pa.us
Whole thread Raw
In response to value too long error  ("Rajat Katyal" <rajatk@intelesoftech.com>)
List pgsql-general
"Rajat Katyal" <rajatk@intelesoftech.com> writes:
> Whenever i try to insert the data, size of which is greater than that of co=
> lumn datatype size,  I got the exception value too long for.....=20

> However this was not in postgresql7.2.

IIRC, older versions would just silently truncate the data to the
specified column width.  We concluded that that was not per spec.
7.3 and later make you do it the SQL-spec way, which is to explicitly
truncate the data.  You can do that with a substring operation or by
casting, for instance
    INSERT INTO foo VALUES('an overly long string'::varchar(10));

It's a tad inconsistent that explicit and implicit casts to varchar(N)
act differently, but that's what the SQL spec says to do, AFAICS.
I guess it's reasonable --- the old behavior could result in unintended
data loss.

            regards, tom lane

pgsql-general by date:

Previous
From: Richard Huxton
Date:
Subject: Re: value too long error
Next
From: Tom Lane
Date:
Subject: Re: PostgreSQL insert speed tests