From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Support negative indexes in split_part().
Date: Fri, 13 Nov 2020 18:50:06 +0000
Message-ID: <E1kde98-00059Y-S6@gemulon.postgresql.org> (raw)
Support negative indexes in split_part().
This provides a handy way to get, say, the last field of the string.
Use of a negative index in this way has precedent in the nearby
left() and right() functions.
The implementation scans the string twice when N < -1, but it seems
likely that N = -1 will be the huge majority of actual use cases,
so I'm not really excited about adding complexity to avoid that.
Nikhil Benesch, reviewed by Jacob Champion; cosmetic tweakage by me
Discussion: https://postgr.es/m/cbb7f861-6162-3a51-9823-97bc3aa0b638@gmail.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/ec0294fb2c8287fd673c57701cdcf6c6396b2f60
Modified Files
--------------
doc/src/sgml/func.sgml | 8 +++-
src/backend/utils/adt/varlena.c | 83 ++++++++++++++++++++++++++++-------
src/test/regress/expected/strings.out | 74 ++++++++++++++++++++++++++++++-
src/test/regress/sql/strings.sql | 24 ++++++++++
4 files changed, 172 insertions(+), 17 deletions(-)
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-committers@postgresql.org
Cc: tgl@sss.pgh.pa.us
Subject: Re: pgsql: Support negative indexes in split_part().
In-Reply-To: <E1kde98-00059Y-S6@gemulon.postgresql.org>
References: <E1kde98-00059Y-S6@gemulon.postgresql.org>
* 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