Thread: char(N), varchar(N), varchar, text

char(N), varchar(N), varchar, text

From
Emi Lu
Date:
<small>Good morning, <br /><br /> For performance point of view, are there big differences between: char(N),
varchar(N),varchar, text? <br /></small><p><small>Some comments from google shows: <br /> No difference, under the hood
it'sall varlena. Check this article from Depesz: <a
href="http://www.depesz.com/index.php/2010/03/02/charx-vs-varcharx-vs-varchar-vs-text/">http://www.depesz.com/index.php/2010/03/02/charx-vs-varcharx-vs-varchar-vs-text/</a><br
/>A couple of highlights:</small><small> </small><blockquote><small> </small><p><small>To sum it all up:</small><small>
</small><ul><li><small>char(n)– takes too much space when dealing with values shorter than n, and can lead to subtle
errorsbecause of adding trailing spaces, plus it is problematic to change the limit</small><li><small>varchar(n) – it's
problematicto change the limit in live environment</small><li><small>varchar – just like text</small><li><small>text –
forme a winner – over (n) data types because it lacks their problems, and over varchar – because it has distinct
name</small></ul><small>So, can I assume no big performance differences? <br /> Thanks alot!<br /> Emi<br
/></small></blockquote>

Re: char(N), varchar(N), varchar, text

From
Andrew Dunstan
Date:
On 10/08/2014 10:22 AM, Emi Lu wrote:
> Good morning,
>
> For performance point of view, are there big differences between:
> char(N), varchar(N), varchar, text?
>
> Some comments from google shows:
> No difference, under the hood it's all varlena. Check this article
> from Depesz:
> http://www.depesz.com/index.php/2010/03/02/charx-vs-varcharx-vs-varchar-vs-text/
> A couple of highlights:
>
>     To sum it all up:
>
>       * char(n) – takes too much space when dealing with values
>         shorter than n, and can lead to subtle errors because of
>         adding trailing spaces, plus it is problematic to change the limit
>       * varchar(n) – it's problematic to change the limit in live
>         environment
>       * varchar – just like text
>       * text – for me a winner – over (n) data types because it lacks
>         their problems, and over varchar – because it has distinct name
>
>     So, can I assume no big performance differences?
>     Thanks alot!
>     Emi
>


Why do you need to ask if you already have the answer? Depesz is right.

cheers

andrew


Re: char(N), varchar(N), varchar, text

From
Emi Lu
Date:
>
>>
>> For performance point of view, are there big differences between:
>> char(N), varchar(N), varchar, text?
>>
>> Some comments from google shows:
>> No difference, under the hood it's all varlena. Check this article
>> from Depesz:
>> http://www.depesz.com/index.php/2010/03/02/charx-vs-varcharx-vs-varchar-vs-text/
>> A couple of highlights:
>>
>>     To sum it all up:
>>
>>       * char(n) – takes too much space when dealing with values
>>         shorter than n, and can lead to subtle errors because of
>>         adding trailing spaces, plus it is problematic to change the
>> limit
>>       * varchar(n) – it's problematic to change the limit in live
>>         environment
>>       * varchar – just like text
>>       * text – for me a winner – over (n) data types because it lacks
>>         their problems, and over varchar – because it has distinct name
>>
>>     So, can I assume no big performance differences?
>>     Thanks alot!
>>     Emi
>>
>
>
> Why do you need to ask if you already have the answer? Depesz is right.
Good to hear this. Well, sorry I saw the time is:/2010/03 (might changes
for diff/newer versions).

Thank you for the confirmation.
Emi