sql-metadata icon indicating copy to clipboard operation
sql-metadata copied to clipboard

Method `parser.columns_dict` do not take into account subqueries.

Open cmistiloglou opened this issue 1 year ago • 0 comments

I have the below sql query in MSSQL.

SELECT 
    ap.[AccountId], 
    (SELECT COUNT(*) FROM [Transactions] t WHERE t.[AccountId] = ap.[AccountId]) AS TransactionCount
FROM 
    [AccountProfiles] ap

I am using the Parser class and the columns_dict method contains the SELECT sql clause which do not take into account the subqueries.

parser = Parser(subquery)

tables = parser.tables
columns_dict = parser.columns_dict

As you can see from the sql query and the final output below in json format, in the Tables section registers the table from the subquery. In Select clause it does not contain the TransactionCount and it also takes the Where clause which is contained inside the subquery.

{
      "Tables": [
          "[Transactions]",
          "[AccountProfiles]"
      ],
      "Select": [
          "[AccountProfiles].[AccountId]"
      ],
      "Where": [
          "[Transactions].[AccountId]",
          "[AccountProfiles].[AccountId]",
          "*"
      ]
  }

cmistiloglou avatar Oct 04 '24 08:10 cmistiloglou