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

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

The query results look correct two me. The two queries are not equivalent, and 
I believe they should return different results in this case. The reference 
manual describes the relationship between NULLIF and CASE here: 
http://db.apache.org/derby/docs/10.8/ref/rrefcasenullif.html. You'll see that 
the equivalent CASE expression mentioned there is a little different from the 
one you used in your query.

Perhaps you meant to use COALESCE instead of NULLIF?
                
> NULLIF and CASE return different result
> ---------------------------------------
>
>                 Key: DERBY-5556
>                 URL: https://issues.apache.org/jira/browse/DERBY-5556
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 10.8.1.2
>         Environment: $ uname -a
> Linux hleemus 3.1.4-1-ARCH #1 SMP PREEMPT Tue Nov 29 08:55:45 CET 2011 x86_64 
> AMD Athlon(tm) 64 X2 Dual Core Processor 5000+ AuthenticAMD GNU/Linux
> $ java -version
> java version "1.6.0_22"
> Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
> Java HotSpot(TM) 64-Bit Server VM (build 17.1-b03, mixed mode)
> $ java -Dij.database=jdbc:derby:dbase -classpath 
> /home/hleem/.m2/repository/org/apache/derby/derbytools/10.8.1.2/derbytools-10.8.1.2.jar:/home/hleem/.m2/repository/org/apache/derby/derby/10.8.1.2/derby-10.8.1.2.jar
>  org.apache.derby.tools.ij
> ij version 10.8
> CONNECTION0* -        jdbc:derby:dbase
> * = current connection
> ij> select pr_parent FROM SDB.PARAMS;
> PR_PARENT  
> -----------
> 10         
> 10         
> 10         
> NULL       
> 4 rows selected
> ij> select case when pr_parent is null then 0 else pr_parent end FROM 
> SDB.PARAMS;
> 1          
> -----------
> 10         
> 10         
> 10         
> 0          
> 4 rows selected
> ij> select nullif(pr_parent,0) FROM SDB.PARAMS;
> 1          
> -----------
> 10         
> 10         
> 10         
> NULL       
> 4 rows selected
> ij> exit;
> $
>            Reporter: hleem
>              Labels: case, nullif
>
> NULLIF and CASE return different result with null INTEGER value.
> 'pr_parent' in query is INTEGER type.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to