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

ROW variables do not get assigned from subselects

    XMLWordPrintable

Details

    Description

      This script using the SELECT..INTO syntax correctly initializes a ROW variable:

      CREATE OR REPLACE TABLE t1 (a INT, b TEXT);
      INSERT INTO t1 VALUES (1,'b1');
      DELIMITER $$
      BEGIN NOT ATOMIC
        DECLARE r ROW TYPE OF t1;
        SELECT * INTO r FROM t1 WHERE a=1;
        SELECT r.a, r.b;
      END;
      $$
      DELIMITER ;
      

      +------+------+
      | r.a  | r.b  |
      +------+------+
      |    1 | b1   |
      +------+------+
      

      so far so good.

      However if I modify the script slightly and replace SELECT..INTO to an equivalent SET, it does not work:

      CREATE OR REPLACE TABLE t1 (a INT, b TEXT);
      INSERT INTO t1 VALUES (1,'b1');
      DELIMITER $$
      BEGIN NOT ATOMIC
        DECLARE r ROW TYPE OF t1;
        SET r=(SELECT * FROM t1 WHERE a=1);
        SELECT r.a, r.b;
      END;
      $$
      DELIMITER ;
      

      +------+------+
      | r.a  | r.b  |
      +------+------+
      | NULL | NULL |
      +------+------+
      

      Another equivalent script with a subselect in the DEFAULT clause of a variable declaration also does not work:

      CREATE OR REPLACE TABLE t1 (a INT, b TEXT);
      INSERT INTO t1 VALUES (1,'b1');
      DELIMITER $$
      BEGIN NOT ATOMIC
        DECLARE r ROW TYPE OF t1 DEFAULT (SELECT * FROM t1 WHERE a=1);
        SELECT r.a, r.b;
      END;
      $$
      DELIMITER ;
      

      +------+------+
      | r.a  | r.b  |
      +------+------+
      | NULL | NULL |
      +------+------+
      

      It should be fixed to have the secord and the third script produce equal results to the first script.

      Attachments

        Issue Links

          Activity

            People

              bar Alexander Barkov
              bar Alexander Barkov
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.