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

Issue with * while using it inside a sub_query

Open ghost opened this issue 4 years ago • 3 comments

Hi, While trying to extract the columns from the below query I'm getting a value error "ValueError: 'posted_dt' is not in list".

  1. SELECT app.acty_dt , base.posted_dt FROM DB.SCH.WTBL app
  2. INNER JOIN( SELECT pro.* FROM DB.SCH.DATET pro INNER JOIN DB.SCH.LIFT lif ON pro.LIFE_SK = lif.LIFE_SK) base
  3. ON app.acty_dt = substr(APP_NR, 1, length(rtrim(APP_NR))-3)
  4. AND base.posted_dt >= '2021-09-01

The reason for the error is that because posted_dt date column is not explicitly mentioned inside the sub_query base, But the posted_dt column is present in the table DATET and inside the sub_query base the table DATET is called by using the * (Refer line 2).

If the Parser provides a way to handle this situation it would be great.

ghost avatar Sep 20 '21 08:09 ghost

I think we support it if you just use *, i think we don't support ones with prefix as of now (like prefix.*).

collerek avatar Sep 20 '21 08:09 collerek

Yeah I'm able to retrieve the columns if I remove the perfix. Anyway hope a fix will be implemented to parse the perfix.* as well.

ghost avatar Sep 20 '21 09:09 ghost

I made a PR for this #296 . Hopefully it can resolve this issue.

sumartoyo avatar Mar 11 '22 15:03 sumartoyo