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

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
Thread:
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

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2020-04-02 21:46:06 Re: BUG #16333: position() function not equivalent to strpos() function when comparing citext
Previous Message Tom Lane 2020-04-02 16:05:59 Re: BUG #16338: casting interval '24h' to time returns '00:00:00' instead of '24:00:00'