Six years for a function: digits(n, offset, length)
substr works on strings, but there was nothing for slicing digits out of a number. I asked in 2020; a first-time contributor picked up the easy-task label in 2026 and it shipped in 26.7.
Source: github.com
ClickHouse has substring for strings but nothing for slicing digits out of a number. The third and fourth digits of 1234567890 meant toUInt32(substring(toString(n), 3, 2)), which is tolerable once and miserable when an identifier carries meaning by position and you need several slices per query. I asked in 2020 for digits(n, offset, length), counting from the left, and mentioned a reversed variant.
The first reply called it a very special case; after I described the identifier use case a maintainer said “That’s reasonable” and suggested division and remainder by a power of ten instead of a trip through strings. The issue was labelled easy task and sat for six years. In June 2026 a first-time contributor asked to take it, and PR #109012 merged on 2026-07-13, shipping in 26.7. The changelog entry: digits(n, offset[, length]) returns the number starting at the 1-indexed offset with length digits, or everything to the end if length is omitted. I found no reversed variant.
26.4 predates it, so the function is unknown there. The two spellings that work without it:
SELECT toUInt32(substring(toString(1234567890), 3, 2)) AS via_string,
intDiv(1234567890, pow(10, 6)) % 100 AS via_arithmetic;
34 34
The arithmetic form needs you to know the digit count, and that bookkeeping is the reason to want a function.
Discussion
Comments live in GitHub Discussions. Sign in with GitHub to join in.