Re: varchar(n) vs. varchar - Mailing list pgsql-general

From Tom Lane
Subject Re: varchar(n) vs. varchar
Date
Msg-id 11923.1156282014@sss.pgh.pa.us
Whole thread Raw
In response to varchar(n) vs. varchar  ("Daniel Serodio" <dserodio@gmail.com>)
List pgsql-general
"Daniel Serodio" <dserodio@gmail.com> writes:
> I've found a thread discussing the use of "text" vs. "varchar"; what
> I'd like to know if there's any performance difference between using
> "varchar(n)" vs. "varchar", ie, should I constrain a "name" column to
> an arbitrary length to improve performance, or will it actually degrade
> performance because of the extra cycles used for checking the length?

The latter.

The general rule of thumb is don't use varchar(n) (or even worse,
char(n)) unless you can point to a specific application requirement
for a maximum field width.  In particular, if you find yourself
picking a value for N out of the air, you're doing the wrong thing.

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: error msg when pg_restore
Next
From: Tom Lane
Date:
Subject: Re: [8.1.4] Create index on timestamp fails