假设用户试图将一个数字(出生年份)投射到一个日期。
select year_of_birth, cast(year_of_birth as date) from visit_occurrence
并收到此错误:
cannot cast type smallint to date
什么是正确的方法? 例如,施放(施放(YOB为字符串)+' -01-01'作为日期)也不起作用。
答案 0 :(得分:2)
使用
select year_of_birth, to_date(cast(year_of_birth as text), 'YYYY') from visit_occurrence ;