- The motivation here was to easily and accurately generate data samples for the nested ranges challenge.
A table contains a single column of text type. The text contains one or more lines where each lines contains one or more sections created from letters. The goal is to write a query that returns a tuple for each section with its start point ,end point and value.
Data sample
create table t (txt varchar (1000));
insert into t (txt) values
(
'
AAAAAAAAAAAAAAAAAAAAAAAAAAAA BBBB CCCCCCCCCCCCCCCCCCCCCCCCC
DDDE FFFFFFFF GGGGGGGGG HHHHHHHH IIIIIII
JJ KKKLLL MM NN OOOOO
P QQ
'
)
;
Requested results
* Only the last 3 columns (section start/end/val) are required, the rest are for debugging purposes.
line_ind section_ind section_length section_start section_end section_val
1 1 28 1 28 A
1 2 4 31 34 B
1 3 25 39 63 C
2 1 3 1 3 D
2 2 1 4 4 E
2 3 8 7 14 F
2 4 9 19 27 G
2 5 8 43 50 H
2 6 7 55 61 I
3 1 2 1 2 J
3 2 3 9 11 K
3 3 3 12 14 L
3 4 2 22 23 M
3 5 2 25 26 N
3 6 5 57 61 O
4 1 1 13 13 P
4 2 2 60 61 Q