Re: BUG #18051: char(N) and varchar(N) behave opposite to the documentation - Mailing list pgsql-bugs

From Félix GERZAGUET
Subject Re: BUG #18051: char(N) and varchar(N) behave opposite to the documentation
Date
Msg-id CANVwZtvyiT3Vz-RB8V-nvzt4tjZ-C8ucaBpVZ77w5v_xMOFTVA@mail.gmail.com
Whole thread Raw
In response to Re: BUG #18051: char(N) and varchar(N) behave opposite to the documentation  (Nicolas Gouteux <nicolas.gouteux@sonarsource.com>)
List pgsql-bugs
Hello Nicolas,

On Wed, Aug 9, 2023 at 4:47 PM Nicolas Gouteux <nicolas.gouteux@sonarsource.com> wrote:
I was just trying to show more junior programmers the difference between the 'assumed' padded char and the more modern 'trimming' varchar
So imagine my surprise when both length() and concatenation() yielded the exactly opposite behavior than expected!

For such pedagogic purpose you can use:

select length(cast('A' as char(4))::bytea)

But you then have to explain the ::bytea trick :-)

Best Regards,

pgsql-bugs by date:

Previous
From: Nicolas Gouteux
Date:
Subject: Re: BUG #18051: char(N) and varchar(N) behave opposite to the documentation
Next
From: David Rowley
Date:
Subject: Re: BUG #18051: char(N) and varchar(N) behave opposite to the documentation