Re: split_part for the last element - Mailing list pgsql-general

From Tom Lane
Subject Re: split_part for the last element
Date
Msg-id 222396.1603478100@sss.pgh.pa.us
Whole thread Raw
In response to Re: split_part for the last element  ("David G. Johnston" <david.g.johnston@gmail.com>)
Responses Re: split_part for the last element  (Nikhil Benesch <nikhil.benesch@gmail.com>)
List pgsql-general
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Fri, Oct 23, 2020 at 8:47 AM Nikhil Benesch <nikhil.benesch@gmail.com>
> wrote:
>> Is there another option I'm missing? Would there be interest in
>> extending split part so that negative indices counted from the end, as
>> in:
>>     split_part('foo bar baz', ' ', -1) -> 'baz'

> I'm torn here because this would be the first usage of this concept in
> PostgreSQL (I think).

We already have some JSON functions that act like that, not to mention
the left() and right() string functions, so I don't see that much of an
argument against extending split_part to do it.

> Tangentially, I noticed that we have a "starts_with" function but no
> corresponding "end_with".
> It's been a while but there used to be a systemic inertia working
> against adding minor useful functions such as these.

Part of the reason for that bias is that these one-off functions tend
not to be very well thought out or complete :-(.  The point that
could be raised here is why we have split_part but not any corresponding
regex-based splitter.

            regards, tom lane



pgsql-general by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: split_part for the last element
Next
From: Nikhil Benesch
Date:
Subject: Re: split_part for the last element