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

Explicit column name error in CTE of UNION

Details

    Description

      Reproduce

      WITH cte (col1) AS
      (
        SELECT 1
        UNION
        SELECT 2
      )
      SELECT col1 FROM cte;
      

      Result

      ERROR 1054 (42S22): Unknown column 'col1' in 'field list'
      

      Expected

      Query succeeds.

      Notes

      It works without UNION:

      WITH cte (col1) AS
      (
        SELECT 1
      )
      SELECT col1 FROM cte;
      +------+
      | col1 |
      +------+
      |    1 |
      +------+
      

      Attachments

        Issue Links

          Activity

            alice Alice Sherepa added a comment -

            Probably the same, imported from mysql 8.0 CTE tests:

            CREATE TABLE t1(a int, b int, c int);
            INSERT INTO t1 VALUES(NULL,NULL,NULL),(2,3,4);
            WITH qn (foo, bar) AS (SELECT 1 AS col, 2 AS coll UNION
                                   SELECT a,b FROM t1) 
            SELECT qn1.bar FROM qn qn1;
            

            ERROR 1054 (42S22): Unknown column 'qn1.bar' in 'field list'

            alice Alice Sherepa added a comment - Probably the same, imported from mysql 8.0 CTE tests: CREATE TABLE t1(a int , b int , c int ); INSERT INTO t1 VALUES ( NULL , NULL , NULL ),(2,3,4); WITH qn (foo, bar) AS ( SELECT 1 AS col, 2 AS coll UNION SELECT a,b FROM t1) SELECT qn1.bar FROM qn qn1; ERROR 1054 (42S22): Unknown column 'qn1.bar' in 'field list'

            Pushed in 10.2

            shagalla Galina Shalygina (Inactive) added a comment - Pushed in 10.2

            People

              shagalla Galina Shalygina (Inactive)
              midenok Aleksey Midenkov
              Votes:
              0 Vote for this issue
              Watchers:
              3 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.