Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-8170

String access operator []

    XMLWordPrintable

    Details

      Description

      I propose to introduce a new operators [pos] and [pos:len] to access elements of string types. Where pos - element index, starting from 0, as in c++ stings. Example:

      mysql> CREATE TABLE `test` (
        `id` int(11) NOT NULL AUTO_INCREMENT,
        `data` varchar(100) NOT NULL,
        PRIMARY KEY (`id`)
      ) ENGINE=InnoDB;
       
      mysql> INSERT INTO `test` (`id`,`data`) VALUES(0,'');
      mysql> UPDATE `test` SET `data`[5] = 'xxx';
       
      mysql> SELECT * FROM `test` WHERE `id`=0;
      +-----+----------------------------+
      | sid | data                       |
      +-----+----------------------------+
      |   0 | '     xxx'
      +-----+----------------------------+
       
      mysql> UPDATE `test` SET `data`[3] = 'aaa';
       
      mysql> SELECT * FROM `test` WHERE `id`=0;
      +-----+----------------------------+
      | sid | data                       |
      +-----+----------------------------+
      |   0 | '   aaaxx'
      +-----+----------------------------+
       
      mysql> UPDATE `test` SET `data`[3:1] = 'bbbbbb';
       
      mysql> SELECT * FROM `test` WHERE `id`=0;
      +-----+----------------------------+
      | sid | data                       |
      +-----+----------------------------+
      |   0 | '   baaxx'
      +-----+----------------------------+
       
      mysql> SELECT `data`[4:3] FROM `test` WHERE `id`=0;
      +----------------------------+
      | data                       |
      +----------------------------+
      | 'aax'
      +----------------------------+

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              Mikle Mikle
              Votes:
              4 Vote for this issue
              Watchers:
              9 Start watching this issue

                Dates

                Created:
                Updated:

                  Git Integration