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

use*_*rJT 1 postgresql amazon-redshift

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

select year_of_birth, cast(year_of_birth as date) from visit_occurrence 
Run Code Online (Sandbox Code Playgroud)

并得到这个错误:

cannot cast type smallint to date
Run Code Online (Sandbox Code Playgroud)

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

Has*_*ani 5

select year_of_birth, to_date(cast(year_of_birth as text), 'YYYY') from visit_occurrence ;
Run Code Online (Sandbox Code Playgroud)