Re: BUG #16333: position() function not equivalent to strpos() function when comparing citext

Lists: Postg사설 토토SQL : Postg사설 토토SQL 메일 링리스트 : 2020-04-02 이후 PGSQL-BUGS 01:00
From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: me(at)reynolds(dot)tj
Subject: BUG #16333: position() function not equivalent to strpos() function when comparing citext
Date: 2020-04-01 23:26:29
Message-ID: 16333-dd25eea9d90e244d@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 16333
Logged by: Tyler Reynolds
Email address: me(at)reynolds(dot)tj
PostgreSQL version: 9.6.17
Operating system: Windows 10
Description:

To reproduce:

CREATE DATABASE test;
CREATE EXTENSION citext;

SELECT position('foo'::citext IN 'Foobar'::citext) =
strpos('Foobar'::citext, 'foo'::citext) as "positionEqualsStrpos";

Expected: "positionEqualsStrpos" returns TRUE.
Actual: "positionEqualsStrpos" returns FALSE.

Citext does not create an overload for position() supporting citext
parameters, therefore position(a in b) always runs case-sensitive.


From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: "me(at)reynolds(dot)tj" <me(at)reynolds(dot)tj>, "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #16333: position() function not equivalent to strpos() function when comparing citext
Date: 2020-04-02 01:00:17
Message-ID: CAKFQuwYYnVw_DKFT5mw9AxYMPb0PhHH6HTrA4pN+NSZVFzK4yQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: Postg사설 토토SQL : Postg사설 토토SQL 메일 링리스트 : 2020-04-02 이후 PGSQL-BUGS 01:00

On Wednesday, April 1, 2020, PG Bug reporting form <noreply(at)postgresql(dot)org>
wrote:

> The following bug has been logged on the website:
>
> Bug reference: 16333
> Logged by: Tyler Reynolds
> Email address: me(at)reynolds(dot)tj
> PostgreSQL version: 9.6.17
> Operating system: Windows 10
> Description:
>
> To reproduce:
>
> CREATE DATABASE test;
> CREATE EXTENSION citext;
>
> SELECT position('foo'::citext IN 'Foobar'::citext) =
> strpos('Foobar'::citext, 'foo'::citext) as "positionEqualsStrpos";
>
> Expected: "positionEqualsStrpos" returns TRUE.
> Actual: "positionEqualsStrpos" returns FALSE.
>
> Citext does not create an overload for position() supporting citext
> parameters, therefore position(a in b) always runs case-sensitive.
>

Nor does it claim to so this isn’t a bug. The fact that citext doesn’t
work with the SQL functions seems intentional.

David J.


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: me(at)reynolds(dot)tj
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #16333: position() function not equivalent to strpos() function when comparing citext
Date: 2020-04-02 01:04:44
Message-ID: 12376.1585789484@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
> SELECT position('foo'::citext IN 'Foobar'::citext) =
> strpos('Foobar'::citext, 'foo'::citext) as "positionEqualsStrpos";

> Citext does not create an overload for position() supporting citext
> parameters, therefore position(a in b) always runs case-sensitive.

Well, the citext documentation specifies which functions have
case-insensitive mappings. strpos() is listed, position() is not,
so I'd say it's acting precisely as documented.

We could consider adding position() of course, but there's a
backwards-compatibility issue --- at this point, people may have
queries that depend on the current behavior.

regards, tom lane


From: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, me(at)reynolds(dot)tj
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #16333: position() function not equivalent to strpos() function when comparing citext
Date: 2020-04-02 20:53:17
Message-ID: 9817af55-fbe4-b342-b641-637f1308ef96@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

On 2020-04-02 03:04, Tom Lane wrote:
> PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
>> SELECT position('foo'::citext IN 'Foobar'::citext) =
>> strpos('Foobar'::citext, 'foo'::citext) as "positionEqualsStrpos";
>
>> Citext does not create an overload for position() supporting citext
>> parameters, therefore position(a in b) always runs case-sensitive.
>
> Well, the citext documentation specifies which functions have
> case-insensitive mappings. strpos() is listed, position() is not,
> so I'd say it's acting precisely as documented.

Arguably, there is a misdesign here, however. Any function that does
some kind of text-in-text search where citext could plausbily offer
case-insensitive behavior will automatically fall back to the
case-sensitive version if citext doesn't offer its own variant. The fix
would technically need to be that citext offers its own variant of every
potential such function, which is clearly not possible, or that casts
between text and citext are more restricted, which would make citext
nearly unusable.

Doesn't seem fixable. Collations are probably a better way of dealing
with this.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
Cc: me(at)reynolds(dot)tj, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #16333: position() function not equivalent to strpos() function when comparing citext
Date: 2020-04-02 21:46:06
Message-ID: 28841.1585863966@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com> writes:
> Arguably, there is a misdesign here, however. Any function that does
> some kind of text-in-text search where citext could plausbily offer
> case-insensitive behavior will automatically fall back to the
> case-sensitive version if citext doesn't offer its own variant. The fix
> would technically need to be that citext offers its own variant of every
> potential such function, which is clearly not possible, or that casts
> between text and citext are more restricted, which would make citext
> nearly unusable.

Indeed. There are some hundreds of built-in functions that take one
or more text arguments; how many of them would need citext variants?

> Doesn't seem fixable. Collations are probably a better way of dealing
> with this.

Yeah, now that we can do non-deterministic collations, it seems like
citext is on the road to obsolescence. Do we have a documentation
example of how to build a simple CI collation?

regards, tom lane


From: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: me(at)reynolds(dot)tj, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #16333: position() function not equivalent to strpos() function when comparing citext
Date: 2020-04-05 10:41:51
Message-ID: d86632ce-76fe-5a3e-abd1-f739b0e3e204@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

On 2020-04-02 23:46, Tom Lane wrote:
>> Doesn't seem fixable. Collations are probably a better way of dealing
>> with this.
>
> Yeah, now that we can do non-deterministic collations, it seems like
> citext is on the road to obsolescence. Do we have a documentation
> example of how to build a simple CI collation?

Yes, in PG12 there is a "tip" box in the citext chapter with a link to
the collation documentation which contains a command to create a
case-insensitive collation. So this should be pretty easy to find even
for casual users.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services