Re: Optimization of this SQL sentence

From: Mark Kirkwood <markir(at)paradise(dot)net(dot)nz>
To: Mario Weilguni <mweilguni(at)sime(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org, Alexander Staubo <alex(at)purefiction(dot)net>, Ruben Rubio <ruben(at)rentalia(dot)com>
Subject: Re: Optimization of this SQL sentence
Date: 2006-10-18 10:19:44
Message-ID: 4535FFC0.603@paradise.net.nz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Mario Weilguni wrote:

>>
>> Â Â contacto varchar(255),
>> Â Â fuente varchar(512),
>> Â Â prefijopais varchar(10)
>>
>> Instead, use:
>>
>> Â Â contacto text,
>> Â Â fuente text,
>> Â Â prefijopais text
>>
>> See the PostgreSQL manual for an explanation of varchar vs. text.
>
> Enforcing length constraints with varchar(xyz) is good database design, not a
> bad one. Using text everywhere might be tempting because it works, but it's
> not a good idea.
>

I've always used the rationale:

If you *know* that the data is length constrained, then it is ok to
reflect this in the domain you use - err, thats why they have length
limits! e.g. if you know that 'prefijopais' can *never* be > 10 chars in
length, then varchar(10) is a good choice.

If the data length is unknown or known to be unlimited, then reflect
that in the domain you use - e.g if 'fuente' or 'contacto' have no
reason to be constrained, then just use text.

best wishes

Mark

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Arnaud Lesauvage 2006-10-18 11:21:09 Index on two columns not used
Previous Message Rohit_Behl 2006-10-18 10:10:01 Re: Jdbc/postgres performance