Issue when parsing tables and there is a CTE inside a JOIN statement
See original GitHub issueTrying 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:
- Created 2 years ago
- Comments:5
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @gmarchi, fixed in #249, you can pip install from this branch if it’s urgent.
I think we don’t support the
with
statement in joins as of now, will check.