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

Unknown Column in 'having clause' on qualified access

    XMLWordPrintable

Details

    • Bug
    • Status: Confirmed (View Workflow)
    • Major
    • Resolution: Unresolved
    • 5.5, 10.1, 10.4.5, 10.2, 10.3, 10.4, 10.5, 10.6, 10.7, 10.8, 10.9, 10.10
    • 10.4
    • Parser
    • MariaDB 10.4.5-bionic in Docker on Ubuntu 19.04

    Description

      When I execute the following Code, I get the error message "Unknown column 'B.AJ' in 'having clause'". I expect that the column can be found (like in the GROUP BY clause or in the examples below) and the sql query can be executed properly.

      CREATE SCHEMA A ;
       
      CREATE  TABLE A.B  (AJ INTEGER) ;
       
      -- Unknown column 'B.AJ' in 'having clause
      SELECT  1 AS A FROM A.B CROSS JOIN A.B AS C GROUP BY B.AJ, C.AJ HAVING B.AJ < C.AJ;
      

      If I delete the HAVING clause completely, the statement gets executed, so it knows the column name in the group by clause.

      -- No Error
      SELECT  1 AS A FROM A.B CROSS JOIN A.B AS C GROUP BY B.AJ, C.AJ;
      

      Additionally, If I use SUM(B.AJ) (and SUM(C.AJ)) instead, everything works fine and the query can be executed.

      -- No Error
      SELECT  1 AS A FROM A.B CROSS JOIN A.B AS C GROUP BY B.AJ, C.AJ HAVING SUM(B.AJ) < SUM(C.AJ);
      

      If I use the exact same condition in a WHERE clause, it also works properly:

      -- No Error
      SELECT  1 AS A FROM A.B CROSS JOIN A.B AS C WHERE B.AJ < C.AJ GROUP BY B.AJ, C.AJ ;
      

      Attachments

        Activity

          People

            sanja Oleksandr Byelkin
            Alicen -
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

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