雪花:过滤包含正确日期值的行

时间:2021-03-01 16:15:21

标签: snowflake-cloud-data-platform

在 Variant 列中:有些行包含正确的日期值,有些行包含一些字符串值。

我需要过滤包含正确日期值的行。

1 个答案:

答案 0 :(得分:0)

这应该会为您提供所需的信息:

  with x as 
  ( 
      select parse_json('{"date":"2021-03-01"}') json union select parse_json('{"date":"No Date"}') 
  )
  select sum(case when try_to_date(x.json:date::string) is not null  then 1 else 0 end) valid_dates,
         sum(case when try_to_date(x.json:date::string) is null then 1 else 0 end) invalid_dates
  from   x;