Re: PSQL Data Type: text vs. varchar(n)

From: "Uwe C(dot) Schroeder" <uwe(at)oss4u(dot)com>
To: pgsql-general(at)postgresql(dot)org
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Chris <dmagick(at)gmail(dot)com>, kurt _ <kjs216(at)hotmail(dot)com>
Subject: Re: PSQL Data Type: text vs. varchar(n)
Date: 2006-03-31 05:37:32
Message-ID: 200603302137.32297.uwe@oss4u.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thursday 30 March 2006 21:27, Tom Lane wrote:
> Chris <dmagick(at)gmail(dot)com> writes:
> > kurt _ wrote:
> >> My question: Is a text field just a varchar(Integer.MAX_VALUE)?
> >
> > varchar has a max of 255 characters,
>
> You must be using some other database ;-)
>
> The current Postgres code has a physical limit of 1G bytes for any
> column value (and in practice you'll hit the threshold of pain
> performance-wise at much less than that). The only real difference
> between type "text" and type "varchar(N)" is that you'll incur runtime
> overhead checking that values assigned to varchar columns are not any
> wider than the specified "N".
>
> My own take on this is that you should "say what you mean". If you do
> not have a clear application-oriented reason for specifying a particular
> limit N in varchar(N), you have no business choosing a random value of N
> instead. Use text, instead of making up an N.

Tom, good point. However, if you design an application that at one point
_might_ need to be run on something else than postgres (say oracle or DB2),
your're way better off with a varchar than text.

UC

--
Open Source Solutions 4U, LLC 1618 Kelly St
Phone: +1 707 568 3056 Santa Rosa, CA 95401
Cell: +1 650 302 2405 United States
Fax: +1 707 568 6416

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2006-03-31 05:51:31 Re: PSQL Data Type: text vs. varchar(n)
Previous Message Christopher Browne 2006-03-31 05:27:18 Re: [Slightly OT] data model books/resources?