Re: The same result for with SPACE and without SPACE

Поиск
Список
Период
Сортировка
От Scott Ribe
Тема Re: The same result for with SPACE and without SPACE
Дата
Msg-id 9358F9A5-2926-4046-AD48-0C83C790A523@elevated-dev.com
обсуждение исходный текст
Ответ на Re: The same result for with SPACE and without SPACE  (M Sarwar <sarwarmd02@outlook.com>)
Список 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 по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: The same result for with SPACE and without SPACE
Следующее
От: Scott Ribe
Дата:
Сообщение: Re: The same result for with SPACE and without SPACE