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(at)postgresql(dot)org
Subject: Re: why do i get 2 as answer for select length('aa '::char(6));
Date: 2018-01-17 03:09:16
Message-ID: 13472.1516158556@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:
> as well as select length('aa'::char(6));
> i thought if the string to be stored is shorter than specified length , it
> will be padded with spaces?

It *is* padded, as you can verify with other functions such as
octet_length or pg_column_size. But length() disregards trailing
spaces in char-type values, on the theory that they're semantically
insignificant.

regards, tom lane

In response to

Responses

Browse pgsql-novice by date

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