Re: why do i get 2 as answer for select length('aa '::char(6)); - Mailing list pgsql-novice

From Tom Lane
Subject Re: why do i get 2 as answer for select length('aa '::char(6));
Date
Msg-id 13472.1516158556@sss.pgh.pa.us
Whole thread Raw
In response to why do i get 2 as answer for select length('aa '::char(6));  (john snow <ofbizfanster@gmail.com>)
Responses Re: why do i get 2 as answer for select length('aa '::char(6));
List pgsql-novice
john snow <ofbizfanster@gmail.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


pgsql-novice by date:

Previous
From: john snow
Date:
Subject: Re: why do i get 2 as answer for select length('aa '::char(6));
Next
From: john snow
Date:
Subject: Re: why do i get 2 as answer for select length('aa '::char(6));