From: Scott Ribe <scott_ribe@elevated-dev.com>
To: M Sarwar <sarwarmd02@outlook.com>
Cc: pgsql-admin@lists.postgresql.org <pgsql-admin@lists.postgresql.org>
Subject: Re: The same result for with SPACE and without SPACE
Date: Wed, 14 Jun 2023 16:47:21 -0600
Message-ID: <9358F9A5-2926-4046-AD48-0C83C790A523@elevated-dev.com> (raw)
In-Reply-To: <DM4PR19MB59784B518F25D2C2292CA3FBD35AA@DM4PR19MB5978.namprd19.prod.outlook.com>
References: <DM4PR19MB5978EB964FA1C7B55FFCB02DD35AA@DM4PR19MB5978.namprd19.prod.outlook.com>
<DM4PR19MB59782360E0C452810D70CBE8D35AA@DM4PR19MB5978.namprd19.prod.outlook.com>
<B600CCAA-59E5-4907-8E6D-C645CA24AB1D@elevated-dev.com>
<DM4PR19MB59784B518F25D2C2292CA3FBD35AA@DM4PR19MB5978.namprd19.prod.outlook.com>
> 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 requires padding 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* value will be space-padded to 10.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-admin@postgresql.org
Cc: scott_ribe@elevated-dev.com, sarwarmd02@outlook.com, pgsql-admin@lists.postgresql.org
Subject: Re: The same result for with SPACE and without SPACE
In-Reply-To: <9358F9A5-2926-4046-AD48-0C83C790A523@elevated-dev.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox