db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Knut Anders Hatlen (JIRA)" <j...@apache.org>
Subject [jira] Commented: (DERBY-4284) All Columns become Nullable when Using left join
Date Mon, 31 Aug 2009 14:20:33 GMT

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

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

The problem seems to be related to the cast. Here's some code that exposes the problem without
using the diagnostic tables:

ij> create table t1 (x varchar(10) not null);
0 rows inserted/updated/deleted
ij> create table t2 (y varchar(10) not null);
0 rows inserted/updated/deleted
ij> create view v1 as select x,y from t1 left outer join t2 on 1=1;
0 rows inserted/updated/deleted
ij> describe v1;
COLUMN_NAME         |TYPE_NAME|DEC&|NUM&|COLUM&|COLUMN_DEF|CHAR_OCTE&|IS_NULL&
------------------------------------------------------------------------------
X                   |VARCHAR  |NULL|NULL|10    |NULL      |20        |NO      
Y                   |VARCHAR  |NULL|NULL|10    |NULL      |20        |YES     

2 rows selected
ij> create view v2 as select x,cast(y as char(2))y from t1 left outer join t2 on 1=1;
0 rows inserted/updated/deleted
ij> describe v2;
COLUMN_NAME         |TYPE_NAME|DEC&|NUM&|COLUM&|COLUMN_DEF|CHAR_OCTE&|IS_NULL&
------------------------------------------------------------------------------
X                   |VARCHAR  |NULL|NULL|10    |NULL      |20        |NO      
Y                   |CHAR     |NULL|NULL|2     |NULL      |4         |NO      

2 rows selected

Y is correctly reported as nullable without the cast, but it is reported as non-nullable if
it is cast to CHAR(2).

Without the patch, both X and Y are nullable, which is also wrong. Only Y should be nullable
in these two queries.

> All Columns become Nullable when Using left join
> ------------------------------------------------
>
>                 Key: DERBY-4284
>                 URL: https://issues.apache.org/jira/browse/DERBY-4284
>             Project: Derby
>          Issue Type: Bug
>          Components: JDBC, SQL
>    Affects Versions: 10.5.1.1
>         Environment: Microsoft Windows XP SP3, Sun JDK 6 Update 14
>            Reporter: Chua Chee Seng
>            Assignee: Knut Anders Hatlen
>         Attachments: derby-4284-1a.diff, derby-4284-1b.diff, derby-4284-1b.stat, Main.java
>
>
> Consider following:-
> create table person (
>   id varchar(20) not null,
>   name varchar(100) not null
> );
> create table car (
>   id varchar(20) not null,
>   person_id varchar(20) not null,
>   model varchar(100) not null,
>   plat_no varchar(100) not null
> );
> When select :-
> select
> p.name,
> c.model,
> c.plat_no
> from person p
> left join car c on (p.id = c.person_id);
> From the ResultSet, get the ResultSetMetaData and inspect each column's isNullable()
value, which is always = 1 (always nullable).  Expected : column 'p.name' isNullable = 0 (not
nullable), but I get 'p.name' isNullable = 1 (nullable)

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


Mime
View raw message