Re: why do i get 2 as answer for select length('aa '::char(6));

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: john snow <ofbizfanster(at)gmail(dot)com>
Cc: pgsql-novice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: why do i get 2 as answer for select length('aa '::char(6));
Date: 2018-01-17 03:32:05
Message-ID: 14571.1516159925@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:
> when you say char-type values, do you include varchar?

No. varchar and text consider trailing spaces to be significant.

To my mind, there are very few situations where char(n) is actually
a reasonable choice of datatype. Maybe for US state abbreviations
or the like. If you're even asking this question, it suggests that
you ought to be using varchar/text.

char(n) basically exists to support fixed-field-width data designs that
should have died along with the punched cards that inspired them.

regards, tom lane

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message john snow 2018-01-17 03:37:43 Re: why do i get 2 as answer for select length('aa '::char(6));
Previous Message john snow 2018-01-17 03:23:13 Re: why do i get 2 as answer for select length('aa '::char(6));