Comment 2 for bug 1462433

Revision history for this message
Rafal (andruwn) wrote :

The idea is to make available to work with strings like char array in c++ (character arrays).
operator [index] and operator [index:len] in read querys (SELECT) works as a SUBSTRING(str,pos) and SUBSTRING(str,pos,len). The forms without a len argument return a substring from string starting at position index. The forms with a len argument return a substring len characters long from string str, starting at position index. String elements numbering starting from 0.
Examples:
mysql> SELECT "abv123cdf"[4];
+----------------------------+
 ' 23cdf'
+----------------------------+
mysql> SELECT "abv123cdf"[4:2];
+----------------------------+
 ' 23'
+----------------------------+
mysql> SELECT "abv123cdf"[104:2];
+----------------------------+
 ' '
+----------------------------+
operator [index]=val and operator [index:len]=val in write querys (UPDATE) works as INSERT(str,pos,len,newstr) or RPAD(str,len,padstr) + INSERT(str,pos,len,newstr).
1. String automatically right-padded with space for *char,text strings and NULL for *binary, blob strings to a length of val + index in form without a len argument, or to index+len in form with a len argument.
2. Substring beginning at position index and length of val characters long replaced by the val in form without a len argument. In form with a len argument substring beginning at position index and len characters long replaced by the val.
String elements numbering starting from 0.
Examples:
mysql> INSERT INTO `test` (`data`) VALUES('');
mysql> UPDATE `test` SET `data`[3] = 'abcmef';
mysql> SELECT * FROM `test`;
+----------------------------+
 ' abcmef'
+----------------------------+
mysql> INSERT INTO `test` (`data`) VALUES('');
mysql> UPDATE `test` SET `data`[3:2] = 'abcmef';
mysql> SELECT * FROM `test`;
+----------------------------+
 ' me'
+----------------------------+
mysql> INSERT INTO `test` (`data`) VALUES('11111');
mysql> UPDATE `test` SET `data`[3:5] = 'abcmef';
mysql> SELECT * FROM `test`;
+----------------------------+
 ' 111abcme'
+----------------------------+
mysql> INSERT INTO `test` (`data`) VALUES('11111');
mysql> UPDATE `test` SET `data`[1:1] = 'ab', `data`[3:1] = 'cd';
mysql> SELECT * FROM `test`;
+----------------------------+
 ' 1a1c1'
+----------------------------+