Re: varchar vs varchar(n)

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Ken Benson <Ken(at)infowerks(dot)com>
Cc: "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org>
Subject: Re: varchar vs varchar(n)
Date: 2017-11-13 15:39:52
Message-ID: 30799.1510587592@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Ken Benson <Ken(at)infowerks(dot)com> writes:
> On Sun, Nov 12, 2017 at 2:34 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us<mailto:tgl(at)sss(dot)pgh(dot)pa(dot)us>> wrote:
> 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.

> Is this true – even if the column in question will be used in (or as part of) an INDEX.
> It seems to be the index would work best if the length of the columns involved is a known value.

varchar(n) doesn't have a known length. Even char(n) doesn't have a known
length in the presence of variable-width text encodings. So there are no
optimizations of the sort you're imagining in Postgres.

regards, tom lane

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message pinker 2017-11-13 15:40:27 Re: array_agg cast issue
Previous Message Tom Lane 2017-11-13 15:34:13 Re: array_agg cast issue