pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: Nikhil Benesch <nikhil.benesch@gmail.com>
Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: split_part for the last element
Date: Fri, 23 Oct 2020 14:35:00 -0400
Message-ID: <222396.1603478100@sss.pgh.pa.us> (raw)
In-Reply-To: <CAKFQuwZyK0NOuy5jaaV_VuSh1x7SKyTgcvaM0mwCaxfZ=QNBhg@mail.gmail.com>
References: <CAPWqQZR+-5pAZNSSrnmYczRaX-huemc=oO8URvDZvUA-M=MOBA@mail.gmail.com>
	<CAKFQuwZyK0NOuy5jaaV_VuSh1x7SKyTgcvaM0mwCaxfZ=QNBhg@mail.gmail.com>

"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





view thread (7+ messages)  latest in thread

Message-ID: <222396.1603478100@sss.pgh.pa.us>
Permalink:  ../222396.1603478100@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/222396.1603478100@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, david.g.johnston@gmail.com, nikhil.benesch@gmail.com
  Subject: Re: split_part for the last element
  In-Reply-To: <222396.1603478100@sss.pgh.pa.us>
  References: <CAPWqQZR+-5pAZNSSrnmYczRaX-huemc=oO8URvDZvUA-M=MOBA@mail.gmail.com> <CAKFQuwZyK0NOuy5jaaV_VuSh1x7SKyTgcvaM0mwCaxfZ=QNBhg@mail.gmail.com> <222396.1603478100@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox