【问题标题】:RedShift: How to cast integer with year into a date?RedShift:如何将带有年份的整数转换为日期?
【发布时间】:2014-09-08 08:18:09
【问题描述】:

假设用户尝试将数字(出生年份)转换为日期。

select year_of_birth, cast(year_of_birth as date) from visit_occurrence 

并得到这个错误:

cannot cast type smallint to date

正确的方法是什么? 例如, cast(cast(YOB as string)+'-01-01' as date) 也不起作用。

【问题讨论】:

    标签: postgresql amazon-redshift


    【解决方案1】:

    使用

    select year_of_birth, to_date(cast(year_of_birth as text), 'YYYY') from visit_occurrence ;
    

    【讨论】:

      猜你喜欢
      • 2018-03-21
      • 2020-06-04
      • 1970-01-01
      • 1970-01-01
      • 2020-12-05
      • 1970-01-01
      • 2021-09-26
      • 1970-01-01
      • 2020-11-03
      相关资源
      最近更新 更多