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/[email protected] 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(-)
