Re: split_part for the last element

2020-10-23 Thread Nikhil Benesch
On Fri, Oct 23, 2020 at 2:35 PM Tom Lane wrote: > > "David G. Johnston" writes: > > On Fri, Oct 23, 2020 at 8:47 AM Nikhil Benesch > > 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:

Re: split_part for the last element

2020-10-23 Thread Nikhil Benesch
On Fri, Oct 23, 2020 at 2:21 PM David G. Johnston wrote: > I'm torn here because this would be the first usage of this concept in > PostgreSQL (I think). Yeah, I also have some qualms about this design in the context of Postgres. Particularly because Postgres allows arrays to begin at negative i

Re: split_part for the last element

2020-10-23 Thread Tom Lane
"David G. Johnston" writes: > On Fri, Oct 23, 2020 at 8:47 AM Nikhil Benesch > 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

Re: split_part for the last element

2020-10-23 Thread David G. Johnston
On Fri, Oct 23, 2020 at 8:47 AM Nikhil Benesch 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' > Some thoughts: I'm torn here because this

Re: split_part for the last element

2020-10-23 Thread Nikhil Benesch
> > Regards > > - Mail original - > De: "Nikhil Benesch" > À: pgsql-general@lists.postgresql.org > Envoyé: Vendredi 23 Octobre 2020 17:47:16 > Objet: split_part for the last element > > Hi, > > Suppose I need to split a string on a delimiter and selec

Re: split_part for the last element

2020-10-23 Thread PALAYRET Jacques
Hello, reverse(split_part(reverse('foo bar baz'), ' ', 1)) -> 'baz' Regards - Mail original - De: "Nikhil Benesch" À: pgsql-general@lists.postgresql.org Envoyé: Vendredi 23 Octobre 2020 17:47:16 Objet: split_part for the last element

split_part for the last element

2020-10-23 Thread Nikhil Benesch
Hi, Suppose I need to split a string on a delimiter and select one of the resulting components. If I want a specific component counting from the start, that's easy: split_part('foo bar baz', ' ', 1) -> 'foo' But if I want the last component, I have several less-than-ideal options: 1. (strin