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) 也不起作用。
用
select year_of_birth, to_date(cast(year_of_birth as text), 'YYYY') from visit_occurrence ;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3916 次 |
| 最近记录: |