Monika X
Monika X

Reputation: 342

Casting invalid string date to date in Snowflake

I have a column with invalid date strings in snowflake and I need to cast them to date. I tried with TRY_CAST, TRY_DATE, IS_DATE but nothings seems to work, i.e.

select * from (values (1, TRY_CAST('1985-02-30' as date)));

Invalid expression [TRY_CAST('1985-02-30' AS DATE)] in VALUES clause

Is there an easy way to do a validation on the date itself?

Upvotes: 1

Views: 299

Answers (1)

Lukasz Szozda
Lukasz Szozda

Reputation: 175716

The VALUES requires simple expression or constants. The alternative is SELECT:

select * from (values (1, TRY_CAST('1985-02-30' as date)));
=>
select * from (select 1, TRY_CAST('1985-02-30' as date));

Upvotes: 1

Related Questions