[teiid-issues] [JBoss JIRA] (TEIID-4133) SQL Server requires CAST when using NULL in anchor part of recursive CTE

Steven Hawkins (JIRA) issues at jboss.org
Wed Apr 13 11:30:00 EDT 2016


    [ https://issues.jboss.org/browse/TEIID-4133?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13191384#comment-13191384 ] 

Steven Hawkins commented on TEIID-4133:
---------------------------------------

This goes beyond null values - the exact type / type constraint must match between all columns.  So even using a string literal, or another column, won't work here.  This is odd as SQL Server for just a regular unions will resolve these these just fine.

> SQL Server requires CAST when using NULL in anchor part of recursive CTE
> ------------------------------------------------------------------------
>
>                 Key: TEIID-4133
>                 URL: https://issues.jboss.org/browse/TEIID-4133
>             Project: Teiid
>          Issue Type: Bug
>          Components: JDBC Connector
>    Affects Versions: 8.12.x
>            Reporter: Andrej Šmigala
>            Assignee: Steven Hawkins
>
> Running the following query in teiid:
> {code:sql}
> 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
> {code}
> results in the following source query:
> {code:sql}
> 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
> {code}
> which fails on SQL Server with {noformat}Types don't match between the anchor and the recursive part in column "stringcolumn" of recursive query "a".{noformat}.
> The source query should be 
> {code:sql}
> 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
> {code}
> i.e. the NULL has to be cast to the precise type of the column in the recursive part of the query.



--
This message was sent by Atlassian JIRA
(v6.4.11#64026)



More information about the teiid-issues mailing list