Bug 1326826 - SQL Server requires CAST when using NULL in anchor part of recursive CTE
Summary: SQL Server requires CAST when using NULL in anchor part of recursive CTE
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: JBoss Data Virtualization 6
Classification: JBoss
Component: Teiid
Version: 6.3.0
Hardware: Unspecified
OS: Unspecified
medium
high
Target Milestone: ER3
: 6.3.0
Assignee: Van Halbert
QA Contact: Andrej Smigala
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-04-13 13:30 UTC by Andrej Smigala
Modified: 2016-08-24 11:48 UTC (History)
6 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2016-08-24 11:48:03 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker TEIID-4133 0 Major Closed SQL Server requires CAST when using NULL in anchor part of recursive CTE 2016-06-05 23:43:58 UTC

Description Andrej Smigala 2016-04-13 13:30:16 UTC
Running the following query in teiid:

with a (intkey, stringcolumn, lvl) as

    (

    select intkey, NULL as stringcolumn, 0 as lvl from bqt1.smallb where intkey = 1

    union all 

    select n.intkey, n.stringkey as stringcolumn, rcte.lvl + 1 as lvl from bqt1.smallb n inner join a rcte on n.intkey = rcte.intkey + 1

    )

 select * from a

results in the following source query:

WITH a (intkey, stringcolumn, lvl) AS

    (

    SELECT SmallB.IntKey, NULL AS stringcolumn, 0 AS lvl FROM SmallB WHERE SmallB.IntKey = 1

    UNION ALL

    SELECT n.IntKey, n.StringKey AS stringcolumn, (rcte.lvl + 1) AS lvl FROM SmallB n INNER JOIN a rcte ON n.IntKey = (rcte.intkey + 1)

    )

SELECT a.intkey, a.stringcolumn, a.lvl FROM a

which fails on SQL Server with

Types don't match between the anchor and the recursive part in column "stringcolumn" of recursive query "a".


The source query should be

WITH a (intkey, stringcolumn, lvl) AS

    (

    SELECT SmallB.IntKey, CAST(NULL AS VARCHAR(10)) AS stringcolumn, 0 AS lvl FROM SmallB WHERE SmallB.IntKey = 1

    UNION ALL

    SELECT n.IntKey, n.StringKey AS stringcolumn, (rcte.lvl + 1) AS lvl FROM SmallB n INNER JOIN a rcte ON n.IntKey = (rcte.intkey + 1)

    )

SELECT a.intkey, a.stringcolumn, a.lvl FROM a

i.e. the NULL has to be cast to the precise type of the column in the recursive part of the query.

Comment 2 JBoss JIRA Server 2016-04-13 16:49:06 UTC
Steven Hawkins <shawkins> updated the status of jira TEIID-4133 to Resolved

Comment 3 JBoss JIRA Server 2016-06-05 23:43:59 UTC
Steven Hawkins <shawkins> updated the status of jira TEIID-4133 to Closed


Note You need to log in before you can comment on or make changes to this bug.