Re: split_part for the last element

From: Nikhil Benesch <nikhil(dot)benesch(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: split_part for the last element
Date: 2020-10-23 18:41:57
Message-ID: CAPWqQZT5ynRpC0Tzek_ocU44ZcaLEJXvO2Lf4soTwxB1YTVjKQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Oct 23, 2020 at 2:35 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> "David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
> > On Fri, Oct 23, 2020 at 8:47 AM Nikhil Benesch <nikhil(dot)benesch(at)gmail(dot)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.

Oh, I didn't realize left and right already worked this way. That
makes this design much more compelling, at least to me.

If the consensus is this extension is ok, I'd be happy to prepare a patch.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message W.P. 2020-10-24 05:35:35 What should I read?
Previous Message Nikhil Benesch 2020-10-23 18:38:26 Re: split_part for the last element