Re: value too long - but for which column?

Поиск
Список
Период
Сортировка
От David Johnston
Тема Re: value too long - but for which column?
Дата
Msg-id 025c01cc8dd1$1498a0d0$3dc9e270$@yahoo.com
обсуждение исходный текст
Ответ на value too long - but for which column?  (Alexander Farber <alexander.farber@gmail.com>)
Список pgsql-general
-----Original Message-----
From: pgsql-general-owner@postgresql.org
[mailto:pgsql-general-owner@postgresql.org] On Behalf Of Alexander Farber
Sent: Tuesday, October 18, 2011 3:44 PM
To: pgsql-general
Subject: [GENERAL] value too long - but for which column?

Hello,

I see the errors

ERROR:  value too long for type character varying(32)
CONTEXT:  SQL statement "update pref_users set first_name =  $1 , last_name
=  $2 , female =  $3 , avatar =  $4 , city =  $5 , last_ip =
 $6 , login = now() where id =  $7 "
        PL/pgSQL function "pref_update_users" line 3 at SQL statement

So is there a way which columns
should be widened and is there
a way to turn string truncation into
a warning instead of a fatal error?

Regards
Alex

--------------------------------/Original Message
----------------------------

The most direct way to determine which field is causing the error is to look
at the data and count characters.

You could rewrite the query to be in the following form:

UPDATE ... SET first_name = ?::varchar(32), last_name = ?::varchar(32),
etc...

When type-casting with an explicit constraint the cast truncates silently
(i.e., without any warnings whatsoever).

The database acts as a last line of defense but you ideally want to push
your data validation logic higher in the stack so you can give meaningful
feedback to the user entering the data.  You can use the database metadata
to avoid hard-coding the arbitrary constraints into your software layer.

David J.



В списке pgsql-general по дате отправления:

Предыдущее
От: Alexander Farber
Дата:
Сообщение: value too long - but for which column?
Следующее
От: Scott Marlowe
Дата:
Сообщение: Re: Postgre Performance