RedShift:如何将带有年份的整数转换为日期?

时间:2014-09-08 08:18:10

标签: postgresql amazon-redshift

假设用户试图将一个数字(出生年份)投射到一个日期。

select year_of_birth, cast(year_of_birth as date) from visit_occurrence 

并收到此错误:

cannot cast type smallint to date

什么是正确的方法? 例如,施放(施放(YOB为字符串)+' -01-01'作为日期)也不起作用。

1 个答案:

答案 0 :(得分:2)

使用

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