Fix contrib/ltree's subpath() with negative offset.
Tom Lane <tgl@sss.pgh.pa.us>
Fix contrib/ltree's subpath() with negative offset. subpath(ltree,offset,len) now correctly errors when given an offset less than -n, where n is the number of labels in the given ltree. There was a duplicate block of code that allowed an offset as low as -2n. The documentation says no such thing, so this must have been a copy-and-paste error in the original ltree patch. While here, avoid redundant calculation of "end" and write LTREE_MAX_LEVELS rather than its hard-coded value. Author: Marcus Gartner <m.a.gartner@gmail.com> Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/CAAUGV_SvBO9gWYbaejb9nhe-mS9FkNP4QADNTdM3wdRhvLobwA@mail.gmail.com
Files
| Path | Change | +/− |
|---|---|---|
| contrib/ltree/expected/ltree.out | modified | +2 −0 |
| contrib/ltree/ltree_op.c | modified | +3 −11 |
| contrib/ltree/sql/ltree.sql | modified | +1 −0 |
Discussion
- [PATCH] Fix LTREE subpath with negative offset 2 messages · 2025-10-31 → 2025-11-01