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

Unknown Column in 'having clause' on qualified access

    Details

    • Type: Bug
    • Status: Confirmed (View Workflow)
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 5.5, 10.1, 10.2, 10.3, 10.4.5
    • Fix Version/s: 10.4
    • Component/s: Parser
    • Environment:
      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

            • Assignee:
              sanja Oleksandr Byelkin
              Reporter:
              Alicen -
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated: