Thread

  1. Re: [HACKERS] varchar/char size

    Marc G. Fournier <scrappy@hub.org> — 1998-01-09T17:56:17Z

    On Fri, 9 Jan 1998, Bruce Momjian wrote:
    
    > > Is CHAR padded on disk? Of course it should be padded for 
    > > representation, but for storage, couldn't it be stored just like
    > > TEXT or VARCHAR? Before storing, it could be trimmed, and when
    > > read from storage, it could be padded with spaces on the right.
    > 
    > Well, traditionally, CHAR() is fixed length, and VARCHAR() is variable. 
    > This is how Ingres and Informix handle it.
    
    	But how do we store this to the file system?  If I setup a table
    with a char(20), and one of the records has a value of "a", does it then
    write 1 byte to the file system, or does it write 1 byte ("a") + 19 bytes
    ("")?
    
    	If the second, is there a reason why, as far as writing to the
    file system is concerned, char() can't be treated like varchar()?  I'd
    imagine you could save one helluva lot of "disk space" by doing that, no?
    
    	Then again, thinkiing of it that way, I may as well just use
    varchar() instead, right?
    
    	See, this is what *really* gets me lost...I use text for
    everything, since I really haven't got a clue as to *why* I'd want to use
    either char() or varchar() instead...
    
    	Now, from what I *think* I recall you stating, char() and
    varchar() are more for backwards compatibility?  Compatibility with other
    SQL engines?  If so...as long as we have a type char(), does our backend
    representation have to be any different between char() and text?