Coalesce and Case-When with To_Date not working as expected (Postgres bug?)
Posted
by
ADTC
on Stack Overflow
See other posts from Stack Overflow
or by ADTC
Published on 2013-07-01T03:50:34Z
Indexed on
2013/07/01
4:21 UTC
Read the original article
Hit count: 155
I'm using Postgres 9.1. The following query does not work as expected. Coalesce should return the first non-null value. However, this query returns null (1?) instead of the date (2).
select COALESCE(
TO_DATE('','yyyymmdd'), --(1)
TO_DATE('20130201','yyyymmdd') --(2)
);
--(1) this evaluates independently to null
--(2) this evaluates independently to the date,
and therefore is the first non-null value
What am I doing wrong? Any workaround?
Edit: This may have nothing to do with Coalesce at all. I tried some experiments with Case When constructs; it turns out, Postgres has this big ugly bug where it treats TO_DATE('','yyyymmdd')
as not null, even though selecting it returns null.
© Stack Overflow or respective owner