That’s the way I see it Jean-Luc.

From: Jean-Luc Hainaut<mailto:jean-luc.hain...@unamur.be>
Sent: 27 February 2018 09:56
To: SQLite mailing list<mailto:sqlite-users@mailinglists.sqlite.org>
Subject: Re: [sqlite] Strange concatenation result


Let me suggest an interpretation that seems to comply with the current
implementation of "substr".

1. String X is stored in a (ficticious) infinite array, the cells of
which are indexed -*, ..., -2, -1, 0, 1, 2,.., +*.
2. String X is stored from cell 1 upward.
3. String 'abcd' is stored in cells [1,4]. Cells [-*,0] and [5,+*] are
empty.
4. Parameters X and Y specify a slice of the array.
5. Parameter Y, as described in the documentation, denotes any cell of
the array, even if it doesn't contain a character of X.
6. Parameter Z, as described in the documentation, denotes any slice of
the array, that may (but need not) include characters of X.
7. Function "substr" returns the contents of the non empty cells of this
slice.

Some examples:

select substr('abcd',1,2);   --> slice [1,2]
select substr('abcd',0,2);   --> slice [0,2]
select substr('abcd',0,-2);  --> slice [-2,-1]
select substr('abcd',5,-3);  --> slice [2,4]
select substr('abcd',5,2);   --> slice [5,6]
select substr('abcd',-3,3);  --> slice [2,4]
select substr('abcd',-4,3);  --> slice [1,3]
select substr('abcd',-5,3);  --> slice [0,2]
select substr('abcd',-6,3);  --> slice [-1,1]
select substr('abcd',-7,3);  --> slice [-2,0]
select substr('abcd',2,0);   --> empty slice
select substr('abcd',-5,0);  --> empty slice

+---------------------+
| substr('abcd',1,2)  |
+---------------------+
| ab                  |
+---------------------+
+---------------------+
| substr('abcd',0,2)  |
+---------------------+
| a                   |
+---------------------+
+---------------------+
| substr('abcd',0,-2) |
+---------------------+
|                     |
+---------------------+
+---------------------+
| substr('abcd',5,-3) |
+---------------------+
| bcd                 |
+---------------------+
+---------------------+
| substr('abcd',5,2)  |
+---------------------+
|                     |
+---------------------+
+---------------------+
| substr('abcd',-3,3) |
+---------------------+
| bcd                 |
+---------------------+
+---------------------+
| substr('abcd',-4,3) |
+---------------------+
| abc                 |
+---------------------+
+---------------------+
| substr('abcd',-5,3) |
+---------------------+
| ab                  |
+---------------------+
+---------------------+
| substr('abcd',-6,3) |
+---------------------+
| a                   |
+---------------------+
+---------------------+
| substr('abcd',-7,3) |
+---------------------+
|                     |
+---------------------+
+---------------------+
| substr('abcd',2,0)  |
+---------------------+
|                     |
+---------------------+
+---------------------+
| substr('abcd',-5,0) |
+---------------------+
|                     |
+---------------------+

_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to