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

From john snow
Subject Re: why do i get 2 as answer for select length('aa '::char(6));
Date
Msg-id CAE67tvWV2GpkGr6hUHfWVrHzn71HDqaxyiojxWyR6gCB2gWJ0g@mail.gmail.com
Whole thread Raw
In response to Re: why do i get 2 as answer for select length('aa '::char(6));  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: why do i get 2 as answer for select length('aa '::char(6));
List pgsql-novice
when you say char-type values, do you include varchar? if so, the other results (see later post from first post) i get are inconsistent with the assertion that length() disregards trailing spaces in char-type values, and i don't understand why it's inconsistent. i hope i'm not becoming annoying :-)

On Wed, Jan 17, 2018 at 11:09 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
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: Tom Lane
Date:
Subject: Re: why do i get 2 as answer for select length('aa '::char(6));
Next
From: Tom Lane
Date:
Subject: Re: why do i get 2 as answer for select length('aa '::char(6));