Albretch Mueller wrote:
Varchar or text?
~
Is the length of the data read in always less than 255 bytes ( or
characters?)? ...
It may be more limited than that by application-domain-specific constraints -
e.g., a license plate might be statutorily limited to eight characters.
It might be coincidence that the input happens to fit within 255 characters
when future inputs might not. One cannot make certain statements about
whether "data read in always [being] less than 255 ... characters" based on a
limited sample set, only probabilistic ones, absent reasoning about the
application domain.
Additionally, one could use TEXT for shorter columns if one wanted:
There are no performance differences between these three types,
[character varying(n), character(n) and text]
apart from increased storage size when using the blank-padded
type, and a few extra cycles to check the length when storing
into a length-constrained column. While character(n) has
performance advantages in some other database systems, it has
no such advantages in PostgreSQL. In most situations text or
character varying should be used instead.
<http://www.postgresql.org/docs/8.3/static/datatype-character.html>
DBMSes are about schemata and planning the data structures, not loosey-goosey
typing. (This reminds me of the debate between the loosely-typed language
(e.g., PHP) camp versus the strongly-typed language (C#, Java) camp.) Schemas
are based on analysis of and reasoning about the application domain, not lucky
guesses about a limited sample of inputs.
--
Lew