Re: varchar vs varchar(n)

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: john snow <ofbizfanster(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: varchar vs varchar(n)
Date: 2017-11-12 19:34:52
Message-ID: 21800.1510515292@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

john snow <ofbizfanster(at)gmail(dot)com> writes:
> do postgresql developers just use varchar instead of specifying a limit n
> when dealing with string types? if so, are there any gotcha's i should be
> aware of?

Generally speaking, I would only use varchar(n) when there is a clear
reason traceable to application requirements why there has to be a
limit, and why the limit should be n and not some other number.
Otherwise you're just creating issues for yourself. The habit of
inventing arbitrary limits on text column width is just a hangover
from punched-card days.

Actually, Postgres people tend to use "text" rather than unconstrained
"varchar". In principle those two types behave equivalently; but the
system has to jump through some extra hoops to work with varchar, and
every so often you'll run into a case where "varchar" is not optimized
as well as "text".

regards, tom lane

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message john snow 2017-11-12 21:53:07 Re: varchar vs varchar(n)
Previous Message john snow 2017-11-12 19:19:20 varchar vs varchar(n)