in reply to Getting length of longest value in a column

Get the DB to tell you the maximum length of the field. Assuming a well-trimmed varchar field called 'reason':

select max( len( reason ) ) from table;

If the field is fixed length or can having space padding, then you'd need to trim them up. The functions for that tend to vary from DB to DB.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

Replies are listed 'Best First'.
Re^2: Getting length of longest value in a column
by GrandFather (Saint) on Feb 20, 2012 at 20:52 UTC

    Actually even len/length/char_length varies from DB to DB. Of the two I've worked with (SQLite and MySQL), one returns the number of bytes for length where the other returns the number of characters. Neither provide len. MySQL provides char_length in addition to length to return the character count.

    True laziness is hard work