pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: hcate3@gmail.com
To: pgsql-bugs@postgresql.org
Subject: BUG #14363: CASE against a literal value produces correct against, same expression against a column null doesn't
Date: Mon, 10 Oct 2016 18:56:22 +0000
Message-ID: <20161010185622.1398.15066@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

The following bug has been logged on the website:

Bug reference:      14363
Logged by:          Henry Cate
Email address:      hcate3@gmail.com
PostgreSQL version: 9.5.2
Operating system:   x86_64-pc-linux-gnu
Description:        

With this setup:

drop table if exists t2;
create table t2 (
  order_key int,
  decimal_9_1     decimal(9,1),
  decimal_18_1    decimal(18,1));

insert into t2 values (3, 901.8, null);


This query:

select decimal_9_1, decimal_18_1, ( 
  case decimal_9_1 
     when null then 0 
     when decimal_9_1  then 1 end),  
  case ( 
    case decimal_9_1 
      when null then 0 
      when decimal_9_1  then 1 end)
    when 1 then 2
    when 0 then 3
  end,  
  case ( 
    case decimal_9_1 
      when decimal_18_1 then 0 
      when decimal_9_1  then 1 end)
    when 1 then 2
    when 0 then 3
  end
from t2 ;


produces these results:

 decimal_9_1 | decimal_18_1 | case | case |  case  
-------------+--------------+------+------+--------
       901.8 |       <null> |    1 |    2 | <null>
(1 row)


I expect the last two columns to both have a value of 2.  

The fourth column compares the result of the inner case statement to NULL
and produces the correct result.  The last column compares to a column which
does have NULL, but some how Postgres gets confused and returns NULL.  It
should also be returning 2.



Here is the version information:

ybd_test=# select version();
                                                      version               
                                       
--------------------------------------------------------------------------------------------------------------------
 PostgreSQL 9.5.2 on x86_64-pc-linux-gnu, compiled by clang version
3.8.0-2ubuntu3 (tags/RELEASE_380/final), 64-bit
(1 row)



-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs


view thread (9+ messages)  latest in thread

Message-ID: <20161010185622.1398.15066@wrigleys.postgresql.org>
Permalink:  ../20161010185622.1398.15066@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/20161010185622.1398.15066@wrigleys.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: hcate3@gmail.com
  Subject: Re: BUG #14363: CASE against a literal value produces correct against, same expression against a column null doesn't
  In-Reply-To: <20161010185622.1398.15066@wrigleys.postgresql.org>
  References: <20161010185622.1398.15066@wrigleys.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox