Re: [ltree] Should `SELECT LCA('1.2', '1.2.3');` return '1.2' instead of '1'?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: Julien Grillot <julien(dot)grillot(at)gmail(dot)com>, "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: [ltree] Should `SELECT LCA('1.2', '1.2.3');` return '1.2' instead of '1'?
Date: 2018-07-13 22:54:12
Message-ID: 29778.1531522452@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

"David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
> On Fri, Dec 1, 2017 at 8:32 AM, Julien Grillot <julien(dot)grillot(at)gmail(dot)com>
> wrote:
>> So, in my understanding, both SELECT LCA('1.2', '1.2'); and SELECT
>> LCA('1.2', '1.2.3'); should return ‘1.2’. What do you think about it?

> If indeed one defines "each node to be a descendant of itself" then you
> are correct. Unfortunately your example indicates that this implementation
> does not define ancestry that way. While you may not agree with the
> definition at this point changing the existing function's behavior in this
> manner seems highly undesirable - too much existing code would silently
> break. Adding a leading (due to varargs) boolean argument that specifies
> "end node is ancestor of itself" behavior might be a workable solution.

> Regardless, the docs should be clarified on this point, though, and maybe
> add a code comment somewhere.

This came up again today; I've now adjusted the docs to reflect reality.

If we were to do something about the lack of a function that behaves
the other way, I'd suggest calling it lcp() for "longest common prefix".
Trying to deal with it with an optional argument is going to create
overloading problems.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2018-07-16 08:34:35 BUG #15278: When initialising Streaming Slave if some folders and files are symlinks they are not copied over
Previous Message Tom Lane 2018-07-13 22:50:33 Re: function lca('{}'::ltree[]) caused DB Instance crash