gpt4 book ai didi

postgresql - Redshift : How to cast integer with year into a date?

转载 作者:行者123 更新时间:2023-11-29 13:02:24 26 4
gpt4 key购买 nike

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

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) 也不起作用。

最佳答案

使用

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

关于postgresql - Redshift : How to cast integer with year into a date?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25719945/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com