zhouqingqing / qpmodel

A Relational Optimizer and Executor
MIT License
64 stars 18 forks source link

[bug] Incorrect handling of case expression #207

Closed pkommoju closed 3 years ago

pkommoju commented 3 years ago

CASE behavior is not conforming to the standard.

select case when a1 is not null then a1 else a4 end from a;

produces 3 4 5

The equivalent construct

select coalesce(a1, a4) from a;

produces correct result 0 1 2

A more illustrative statement:

select case a1 when 0 then 'a' when 1 then 'b' when 2 then 'c' else 'd' end from a;

produces a a a

In effect only the first WHEN's THEN clause is output unconditionally.