Support negative indexes in split_part().
Tom Lane <tgl@sss.pgh.pa.us>
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
Files
| Path | Change | +/− |
|---|---|---|
| doc/src/sgml/func.sgml | modified | +7 −1 |
| src/backend/utils/adt/varlena.c | modified | +68 −15 |
| src/test/regress/expected/strings.out | modified | +73 −1 |
| src/test/regress/sql/strings.sql | modified | +24 −0 |
Documentation touched
Discussion
- [PATCH] Support negative indexes in split_part 5 messages · 2020-11-02 → 2020-11-13