After all, when a VARCHAR allows arbitrary Unicode characters, the maximal byte width is four times the character count (for UTF-8, UTF-16 and UTF-32), so a character length of 255 won't lead to a byte length that fits into a byte.
You got it backwards. ;-) When storing UTF-8 characters in a VARCHAR(255), you may not be able to store 255 characters.

The size is the byte length. And 255 takes a single byte to store the length, anything above takes 2 bytes.

Also note that many (var)char columns will not be used to store non-ASCII data. Just because Unicode exists doesn't mean everything requires non-ASCII (or non-LATIN-1) characters.


In reply to Re: [OT] Database row width and cargo cult programming by JavaFan
in thread [OT] Database row width and cargo cult programming by moritz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.