Re: Does the POSITION() function takes into account the COLLATION... or not ?!?

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: pageorge(at)unice(dot)fr, Pg Docs <pgsql-docs(at)lists(dot)postgresql(dot)org>
Subject: Re: Does the POSITION() function takes into account the COLLATION... or not ?!?
Date: 2022-02-16 16:10:08
Message-ID: CAKFQuwavkvERHKc=-Ws=1YEXy68j4GpJx0XbUwbKbY-=hKs7zQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

On Tue, Feb 15, 2022 at 11:17 AM PG Doc comments form <
noreply(at)postgresql(dot)org> wrote:

> The following documentation comment has been logged on the website:
>
> Page: https://www.postgresql.org/docs/14/functions-string.html
> Description:
>
>
> SELECT POSITION(('å' COLLATE "en_US.utf8") IN 'yeah'); -- should return 3
> instead of 0 !?!
> SELECT POSITION(('o' COLLATE "en_US.utf8") IN 'ångström'); -- should return
> 7 instead of 0 !?!
>
> ==> up to here, this seems pretty enough to conclude that POSITION()
> doesn't
> care at all about COLLATION and always perform a byte search.
>

IIUC "Performing a byte search" is what happens when you use a
deterministic collation where the only test is for equality. So your
examples are not useful in distinguishing whether a collation agnostic byte
search or a deterministic collation search is happening.

> I would like to have something in the doc about that... i.e. either some
> examples showing how the COLLATION is impacting the results of the
> POSITION() function

I don't disagree, but lack of documentation regarding string functions and
collations is not just limited to the position function. I find the fact
the word collation doesn't appear anywhere on the string functions page to
be potentially worthy of change.

How collations behave is documented, in particular:

"A collation is either deterministic or nondeterministic. A deterministic
collation uses deterministic comparisons, which means that it considers
strings to be equal only if they consist of the same byte sequence."

I'll admit I'm definitely an unfavorably biased observer here and don't
deal with these nuances on a daily basis. I have the general impression
that our documentation is correct and sufficient but could be made more
user-friendly. Updating a single function doesn't do that though and in
some ways makes things worse when other related elements, and the
presentation of the material as a whole, doesn't go along with that single
change. Based on this, and the above observation about your test cases, I
don't see much motivation for change here. The effort seems to outweigh
the reward. But for someone who feels differently and submits a patch
there is, IMO, room enough for improvement that a well-written one is
likely to be welcomed.

David J.

In response to

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message Tom Lane 2022-02-16 16:18:46 Re: Does the POSITION() function takes into account the COLLATION... or not ?!?
Previous Message Peter Eisentraut 2022-02-16 14:07:08 Re: Does the POSITION() function takes into account the COLLATION... or not ?!?