Search Postgresql Archives

Re: varchar(n) VS text

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"Pierre Thibaudeau" <pierdeux@xxxxxxxxx> writes:
> I am puzzling over this issue:

> 1) Is there ever ANY reason to prefer "varchar(n)" to "text" as a column type?

In words of one syllable: no.

Not unless you have an application requirement for a specific maximum
length limit (eg, your client code will crash if fed a string longer
than 256 bytes, or there's a genuine data-validity constraint that you
can enforce this way).

Or if you want to have schema-level portability to some other DB that
understands varchar(N) but not text.  (varchar(N) is SQL-standard,
while text isn't, so I'm sure there are some such out there.)

> From my reading of the dataype documentation, the ONLY reason I can
> think of for using "varchar(n)" would be in order to add an extra
> data-type constraint to the column.

That is *exactly* what it does.  No more and no less.  There's no
performance advantage, in fact you can expect to lose a few cycles
to the constraint check.

			regards, tom lane


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux