Re: value too long for type character varying(25) - Mailing list pgsql-novice

From Tom Lane
Subject Re: value too long for type character varying(25)
Date
Msg-id 20374.1037715065@sss.pgh.pa.us
Whole thread Raw
In response to value too long for type character varying(25)  (Frank Yip <frankyip@nasitron.com>)
List pgsql-novice
Frank Yip <frankyip@nasitron.com> writes:
> which say "Prior to PostgreSQL 7.2, strings that were too long were
> silently truncated, no error was raised."
> does anyone know if there is a option to set it truncate the strings?

No.  But in 7.3 you can do something like

    insert into foo values('your data here'::varchar(25));

An explicit coercion to varchar(n) will truncate the data without error.
An implicit coercion will raise an error.  Yes, it's pretty bizarre,
but it's what the SQL spec says to do when you read it closely enough.

            regards, tom lane

pgsql-novice by date:

Previous
From: Rod Kreisler
Date:
Subject: Re: Why am I getting this message sometimes?
Next
From: Oliver Elphick
Date:
Subject: Re: [SQL] Problems invoking psql. Help please.