[ 
https://issues.apache.org/jira/browse/DERBY-4420?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12770562#action_12770562
 ] 

Knut Anders Hatlen commented on DERBY-4420:
-------------------------------------------

It looks like setTableConstructorTypes() is only meant for table constructors 
(values clauses). UnionNode overrides it and makes it a no-op unless the union 
really is a values clause that has been rewritten to a union. 
IntersectOrExceptNode does not override it. I tried implementing an empty 
override in IntersectOrExceptNode, and that made the NPE go away. Probably, the 
code in ResultSetNode.setTableConstructorTypes() should only be executed if the 
node is a RowResultSetNode, so an alternative solution would be to move the 
method to RowResultSetNode and make the method in ResultSetNode a no-op.

The change fixes the NPE, and the query with no generated columns, identity 
columns or default values works correctly. The queries that insert into a table 
with a column that's auto-generated somehow, this error is raised instead:

ERROR 42X77: Column position '2' is out of range for the query expression.

So either it's the wrong fix, or there's more than one bug.

> NullPointerException with INSERT INTO ... from EXCEPT/INTERSECT
> ---------------------------------------------------------------
>
>                 Key: DERBY-4420
>                 URL: https://issues.apache.org/jira/browse/DERBY-4420
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 10.1.1.0, 10.2.1.6, 10.3.1.4, 10.4.1.3, 10.5.1.1, 
> 10.5.3.0, 10.6.0.0
>            Reporter: Knut Anders Hatlen
>         Attachments: npe.sql
>
>
> The sequence of statements below give a NullPointerException. The statements 
> are very similar to the ones in DERBY-4419, but this is a separate bug since 
> the stack traces are different, and this bug can be seen all the way back to 
> 10.1.1.0, whereas DERBY-4419 was a regression in 10.3. (On 10.0.2.1, a syntax 
> error is raised instead of the NPE.)
> ij> create table t1(x int);
> 0 rows inserted/updated/deleted
> ij> insert into t1 values 1,2;
> 2 rows inserted/updated/deleted
> ij> create table t2(x int);
> 0 rows inserted/updated/deleted
> ij> insert into t2 values 2,3;
> 2 rows inserted/updated/deleted
> ij> create table t3(x int, y int generated always as identity);
> 0 rows inserted/updated/deleted
> ij> insert into t3(x) select * from t1 except select * from t2;
> ERROR XJ001: Java exception: ': java.lang.NullPointerException'.
> Same error if INTERSECT is used instead of EXCEPT.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to