Re: [SQL] Comparison semantics of CHAR data type

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Thomas Fanghaenel <tfanghaenel(at)salesforce(dot)com>
Cc: Kevin Grittner <kgrittn(at)ymail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [SQL] Comparison semantics of CHAR data type
Date: 2014-02-14 22:02:26
Message-ID: 20140214220226.GA18670@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-sql

On Thu, Feb 13, 2014 at 09:47:01PM -0500, Bruce Momjian wrote:
> On Wed, Oct 16, 2013 at 02:17:11PM -0400, Bruce Momjian wrote:
> > > > You can see the UTF8 case is fine because \n is considered greater
> > > > than space, but in the C locale, where \n is less than space, the
> > > > false return value shows the problem with
> > > > internal_bpchar_pattern_compare() trimming the string and first
> > > > comparing on lengths. This is exactly the problem you outline, where
> > > > space trimming assumes everything is less than a space.
> > >
> > > For collations other than C some of those issues that have to do with
> > > string comparisons might simply be hidden, depending on how strcoll()
> > > handles inputs off different lengths: If strcoll() applies implicit
> > > space padding to the shorter value, there won't be any visible
> > > difference in ordering between bpchar and varchar values. If strcoll()
> > > does not apply such space padding, the right-trimming of bpchar values
> > > causes very similar issues even in a en_US collation.
>
> I have added the attached C comment to explain the problem, and added a
> TODO item to fix it if we ever break binary upgrading.
>
> Does anyone think this warrants a doc mention?

I have done some more thinking on this and I found a way to document
this, which reduces our need to actually fix it some day. I am afraid
the behavioral change needed to fix this might break so many
applications that the fix will never be done, though I will keep the
TODO item until I get more feedback on that. Patch attached.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ Everyone has their own god. +

Attachment Content-Type Size
char.diff text/x-diff 2.7 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Kevin Grittner 2014-02-14 22:57:37 Ctrl+C from sh can shut down daemonized PostgreSQL cluster
Previous Message Alvaro Herrera 2014-02-14 21:32:27 Re: Per table autovacuum vacuum cost limit behaviour strange

Browse pgsql-sql by date

  From Date Subject
Next Message ssylla 2014-02-15 10:03:33 Re: Trigger function - variable for schema name [SOLVED]
Previous Message Bruce Momjian 2014-02-14 02:47:01 Re: [SQL] Comparison semantics of CHAR data type