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

Bogus error executing PS for query using CTE with renaming of columns

    XMLWordPrintable

Details

    Description

      create table t1 (a int, b int);
       
      with cte (c1,c2) as (select a as col1, sum(b) as col2 from t1 group by col1) select * from cte;
      

      so far so good.

      prepare st from 'with cte (c1,c2) as (select a as col1, sum(b) as col2 from t1 group by col1) select * from cte';
      execute st;
      

      ERROR 1054 (42S22): Unknown column 'col1' in 'group statement'

      swapping the original column name back in...

      prepare st from 'with cte (c1,c2) as (select a as col1, sum(b) as col2 from t1 group by a) select * from cte';
      execute st;
      

      is OK

      order by clause is similar

      with cte (c1,c2) as (select a as col1, sum(b) as col2 from t1 order by col1) select * from cte;
      

      is OK.

      prepare st from 'with cte (c1,c2) as (select a as col1, sum(b) as col2 from t1 order by col1) select * from cte';
      execute st;
      

      ERROR 1054 (42S22): Unknown column 'col1' in 'order clause'

      interestingly (by design) the where clause is treated differently

      select a as col1, sum(b) as col2 from t1 where col1 is not null;
      

      ERROR 1054 (42S22): Unknown column 'col1' in 'where clause'

      Attachments

        Issue Links

          Activity

            People

              Johnston Rex Johnston
              Johnston Rex Johnston
              Votes:
              0 Vote for this issue
              Watchers:
              6 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.