How to handle blank space in Snowflake

Viewed 802

I am trying to replace null values with a blank space but its throwing an error in snowflake.

select 
    case when CALL_DATE IS NULL then ' ' ELSE CALL_DATE end as CALL_DATE_NEW
from Table_x
2 Answers

The problem is the derived column CALL_DATE_NEW gets implicitly cast to type timestamp. As the error indicates, you can't specify a space as a timestamp. You can; however, specify a timestamp as a varchar:

create or replace temp table X (CALL_DATE timestamp);
insert into X values ('2021-12-03'), (null);

select case when CALL_DATE IS NULL then ' ' ELSE CALL_DATE end as CALL_DATE_NEW from x; -- Timestamp '' is not recognized

select case when CALL_DATE IS NULL then ' ' ELSE to_varchar(CALL_DATE) end as CALL_DATE_NEW from x; -- Works by keeping the types consistent

Date data types can be null or contain data and/or time data. They cannot contain Space. Sorry.

Related