Обсуждение: value too long for type character varying(25)

Поиск
Список
Период
Сортировка

value too long for type character varying(25)

От
Frank Yip
Дата:
Hi, I got this error after I upgraded to 7.2.1
I found the document from the below link.

    http://www.postgresql.org/idocs/index.php?datatype-character.html

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?

Thanks alot.

Frank


Re: value too long for type character varying(25)

От
Tom Lane
Дата:
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