RE: Ltree pattern matching

From: Terry Gilbert <Terry(dot)Gilbert(at)sas(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "pgsql-docs(at)lists(dot)postgresql(dot)org" <pgsql-docs(at)lists(dot)postgresql(dot)org>
Subject: RE: Ltree pattern matching
Date: 2021-11-12 16:04:29
Message-ID: MN2PR05MB69103A367F4C2E3D362F8480F1959@MN2PR05MB6910.namprd05.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

So, when it says "* prefix matching matches each word separately" it means
foo_bar* will match a label with the first word beginning with foo and a second word beginning with bar?

Hmmm I'll think about it, maybe I can suggest helpful wording.
Thank you for clarifying!
Terry

-----Original Message-----
From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Sent: Friday, November 12, 2021 10:37 AM
To: Terry Gilbert <terry(dot)gilbert(at)sas(dot)com>
Cc: pgsql-docs(at)lists(dot)postgresql(dot)org
Subject: Re: Ltree pattern matching

EXTERNAL

PG Doc comments form <noreply(at)postgresql(dot)org> writes:
> In v12 ltree doc (I've not checked other versions) "The behavior of %
> is a bit complicated. It tries to match words rather than the entire
> label. For example foo_bar% matches foo_bar_baz but not foo_barbaz. If
> combined with *, prefix matching applies to each word separately, for
> example foo_bar%* matches foo1_bar2_baz but not foo1_br2_baz.

> I believe foo1 is in error (if I understood the operators), it should
> be foo.

A quick test shows that the examples are correct as stated:

contrib_regression=# select 'foo_bar_baz'::ltree ~ 'foo_bar%'::lquery; ?column?
----------
t
(1 row)

contrib_regression=# select 'foo_barbaz'::ltree ~ 'foo_bar%'::lquery; ?column?
----------
f
(1 row)

contrib_regression=# select 'foo1_bar2_baz'::ltree ~ 'foo_bar%*'::lquery; ?column?
----------
t
(1 row)

contrib_regression=# select 'foo1_br2_baz'::ltree ~ 'foo_bar%*'::lquery; ?column?
----------
f
(1 row)

I'd be the first to admit that this paragraph doesn't seem to measure up to our usual standards of clarity, but I'm not sure about what would be better wording.

regards, tom lane

In response to

Browse pgsql-docs by date

  From Date Subject
Next Message Tom Lane 2021-11-14 18:13:39 Re: Why clear pg_wal when recovering?
Previous Message Mikael Sterner 2021-11-12 15:55:48 Why clear pg_wal when recovering?