Field with character varying (255)
Field with character varying (255)
От:
"Christopher A. Goodfellow" <cgoodfellow@tealuxe.com>
Дата:
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. Postgresql version 7.3.2. This problem did not occur in postgresql version 6.5 and the values were truncated. Output from \d of the filed in question below.... Column | Type | Modifiers ---------------+------------------------+----------------------------------- ------------------------ questions | character varying(255) | Thank You, Christopher A. Goodfellow Director of Information Technology Tealuxe, Inc. Phone: 508 520 7887 ex:22 Fax: 508 528 8999 www.tealuxe.com tea for all
Re: Field with character varying (255)
От:
Bruno Wolff III <bruno@wolff.to>
Дата:
On Mon, Apr 26, 2004 at 12:48:43 -0400,
"Christopher A. Goodfellow" 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)