title: Why specify a length for character varying types
body: <p>Referring to the Postgres Documentation on <a href="http://www.postgresql.org/docs/current/static/datatype-character.html" rel="noreferrer">Character Types</a>, I am unclear on the point of specifying a length for character varying (varchar) types.</p>
  
  <p>Assumption:</p>
  
  <ul>
  <li>the length of string doesn't matter to the application.</li>
  <li>you don't care that someone puts that maximum size in the database</li>
  <li>you have unlimited hard disk space</li>
  </ul>
  
  <p>It does mention:</p>
  
  <blockquote>
    <p>The storage requirement for a short string (up to 126 bytes) is 1 byte
    plus the actual string, which includes the space padding in the case
    of character. Longer strings have 4 bytes of overhead instead of 1.
    Long strings are compressed by the system automatically, so the
    physical requirement on disk might be less. Very long values are also
    stored in background tables so that they do not interfere with rapid
    access to shorter column values. In any case, the longest possible
    character string that can be stored is about 1 GB. (The maximum value
    that will be allowed for n in the data type declaration is less than
    that. It wouldn't be useful to change this because with multibyte
    character encodings the number of characters and bytes can be quite
    different.</p>
  </blockquote>
  
  <p>This talks about the size of string, not the size of field, (i.e. sounds like it will always compress a large string in a large varchar field, but not a small string in a large varchar field?)</p>
  
  <p>I ask this question as it would be much easier (and lazy) to specify a much larger size so you never have to worry about having a string too large. For example, if I specify varchar(50) for a place name I will get locations that have more characters (e.g. Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch), but if I specify varchar(100) or varchar(500), I'm less likley to get that problem.</p>
  
  <p>So would you get a performance hit between varchar(500) and (arbitrarily) varchar(5000000) or text() if your largest string was say 400 characters long?</p>
  
  <p>Also out of interest if anyone has the answer to this AND knows the answer to this for other databases, please add that too.</p>
  
  <p>I have googled, but not found a sufficiently technical explanation.</p>