question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue when parsing tables and there is a CTE inside a JOIN statement

See original GitHub issue

Trying to parse tables from this query:

SELECT DWH_DM.COM_MONITOR_OPT_TREND.OC_YM_REF, CALENDAR_OPT_TREND.YM_REF, DWH_DM.COM_MONITOR_OPT_TREND.RULE, OPT_TREND_RANKING.QNTY_YM_NG, DWH_DM.COM_MONITOR_OPT_TREND.ABS_OC, DWH_DM.COM_MONITOR_OPT_TREND.EFFC_CPTY_N3, DWH_DM.COM_MONITOR_OPT_TREND.ABS_PIP, DWH_DM.COM_MONITOR_OPT_TREND.EFFC_CPTY_N3-DWH_DM.COM_MONITOR_OPT_TREND.ABS_OC, DWH_DM.COM_MONITOR_OPT_TREND.EFFC_CPTY_N3-DWH_DM.COM_MONITOR_OPT_TREND.ABS_PIP
FROM ( 
	SELECT RULE , EFFC_CPTY_N3-ABS_PIP QNTY_YM_NG 
	FROM DWH_DM.COM_MONITOR_OPT_TREND 
	WHERE OC_YM_REF = (
	SELECT MAX(OC_YM_REF)
	FROM DWH_DM.COM_MONITOR_OPT_TREND LAST_MONTH) 
	ORDER BY (EFFC_CPTY_N3-ABS_PIP) DESC ) OPT_TREND_RANKING 
RIGHT OUTER JOIN DWH_DM.COM_MONITOR_OPT_TREND ON (DWH_DM.COM_MONITOR_OPT_TREND.RULE=OPT_TREND_RANKING.RULE) 
INNER JOIN ( 
	WITH CTE_RANGE AS ( 	SELECT TO_CHAR(ADD_MONTHS(TO_DATE(MAX(OC_YM_REF), 'YYYYMM'),-11),'YYYYMM') AS START_MONTH, MAX(OC_YM_REF) AS END_MONTH 	FROM DWH_DM.COM_MONITOR_OPT_TREND ) 
	SELECT YM_REF, TO_CHAR(TO_DATE(YM_REF,'YYYYMM'), 'Mon', 'NLS_DATE_LANGUAGE = ENGLISH') MONTH_REF 
	FROM DWH_DM.FER_D_CALENDAR_MONTH_SLS 
	INNER JOIN CTE_RANGE 	ON YM_REF BETWEEN CTE_RANGE.START_MONTH AND CTE_RANGE.END_MONTH ORDER BY YM_REF ) CALENDAR_OPT_TREND ON (CALENDAR_OPT_TREND.YM_REF=DWH_DM.COM_MONITOR_OPT_TREND.OC_YM_REF) 
WHERE ( DWH_DM.COM_MONITOR_OPT_TREND.RULE NOT IN ('DELY') )

I get the following:

['DWH_DM.COM_MONITOR_OPT_TREND', 'WITH', 'DWH_DM.FER_D_CALENDAR_MONTH_SLS']

I think the WITH statement shouldn’t be in the output.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
collerekcommented, Oct 23, 2021

Hi @gmarchi, fixed in #249, you can pip install from this branch if it’s urgent.

1reaction
collerekcommented, Sep 13, 2021

I think we don’t support the with statement in joins as of now, will check.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Parsing error in in CTE query SQL server - Stack Overflow
Specifies a column name in the common table expression. Duplicate names within a single CTE definition are not allowed.
Read more >
Why is my CTE so slow? - SQLShack
Specifies a temporary named result set, known as a common table expression (CTE). This is derived from a simple query and defined within...
Read more >
WITH common_table_expression (Transact-SQL) - SQL Server
Specifies a temporary named result set, known as a common table expression (CTE). This is derived from a simple query and defined within...
Read more >
If a CTE is defined in a query and is never used, does it make ...
Regarding performance, the unused CTE is parsed and compiled (or at least compiled in the case below), so it is not 100% ignored,...
Read more >
Fundamentals of table expressions, Part 5 – CTEs, logical ...
You can find it in the documentation of Microsoft SQL Server and Azure ... statement preceding a CTE definition, in which case the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found