Обсуждение: Add column-name hint to log messages generated by inserts when varchars don't fit

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

Add column-name hint to log messages generated by inserts when varchars don't fit

От
"Stepan Rutz"
Дата:
Hi everybody again,

(Resending this EMail again because apparently I have just send in HTML format, which wasn't my intention)


on our production servers I have quite some errors due to excessively long varchar-values which application-code tries
toinsert into tables and which don't fit. 
The errors look like

  ERROR:  value too long for type character varying(4)

This is not helping me much. The patch will turn this too

  ERROR:  value too long for type character varying(4) (hint: column-name is mycolumn)

if the column that was overflown was mycolumn.



The tables have many columns, the statements are not readable and many columns happen to have the same length. Powers
of2 most often for some odd reason ... 
I fired up gdb and saw that the error message is generated during the preprocessing of the query where some kind of the
constant-folding/constant-eliminationhappens on the parse-tree. I went ahead and added a try/catch at some point
upwardsin the call-stack where at least i have the contact of the T_TargetEntry. That has a field resname which gives
meexactly the information i need... The column which was overflown. With that info i can fix the application code much
moreeasily. Relation name was out of reach for me, there is a void* passed transparently to the constant-mutator but
thatis not checkable at the point. That context contains the original top-level statement node however. 
The patch just adds a bit of hinting to the error message and goes on.. That is all but really helpful to me and
potentiallyalso others. 
Attached Patch has more Infos and comments.
Regards from Germany,
Stepan


Stepan Rutz
Phone: +49 (0) 178 654 9284
Email: stepan.rutz@gmx.de
Earth: Brunnenallee 25a, 50226 Frechen, Germany

Вложения

Re: Add column-name hint to log messages generated by inserts when varchars don't fit

От
Robert Haas
Дата:
On Wed, Aug 5, 2015 at 6:39 AM, Stepan Rutz <Stepan.Rutz@gmx.de> wrote:
> on our production servers I have quite some errors due to excessively long varchar-values which application-code
triesto insert into tables and which don't fit.
 
> The errors look like
>
>   ERROR:  value too long for type character varying(4)
>
> This is not helping me much. The patch will turn this too
>
>   ERROR:  value too long for type character varying(4) (hint: column-name is mycolumn)
>
> if the column that was overflown was mycolumn.

expression_tree_walker is used in enough different places that you
can't really modify that like this.  It'll have too many side effects
that may not be good.

Generally, the way to stick some useful information into the error
message is with an error context callback, rather than by appending to
the primary error message.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company