Reputation: 11934
Assume a user tries to cast a number (year of birth) into a date.
select year_of_birth, cast(year_of_birth as date) from visit_occurrence
And gets this error :
cannot cast type smallint to date
What is the proper way? e.g., cast(cast(YOB as string)+'-01-01' as date) does not work either.
Upvotes: 1
Views: 5687
Reputation: 5194
use
select year_of_birth, to_date(cast(year_of_birth as text), 'YYYY') from visit_occurrence ;
Upvotes: 5