Re: The same result for with SPACE and without SPACE - Mailing list pgsql-admin

From Scott Ribe
Subject Re: The same result for with SPACE and without SPACE
Date
Msg-id 9358F9A5-2926-4046-AD48-0C83C790A523@elevated-dev.com
Whole thread Raw
In response to Re: The same result for with SPACE and without SPACE  (M Sarwar <sarwarmd02@outlook.com>)
List pgsql-admin
> On Jun 14, 2023, at 4:31 PM, M Sarwar <sarwarmd02@outlook.com> wrote:
>
> I expect this to behave the same way whether it comes from CHAR or VARCHAR.

Why would you expect that??? CHAR explicitly means that:

1) shorter strings will be space-padded to the given length
2) if a string is presented with spaces making it longer, it will be truncated

Putting it all together, it implies:

3) trailing spaces are semantically meaningless

Anyway, the closest I could to finding a reference on comparison behavior for this case states: "The ANSI standard
requirespadding for the character strings used in comparisons so that their lengths match before comparing them." 

And there you go, you used CHAR(10), so all values in the table are space-padded to length 10, so for comparison *any*
valuewill be space-padded to 10. 





pgsql-admin by date:

Previous
From: Tom Lane
Date:
Subject: Re: The same result for with SPACE and without SPACE
Next
From: Scott Ribe
Date:
Subject: Re: The same result for with SPACE and without SPACE