Luc
Luc

Reputation: 747

Combine separate month and year in Redshift

base_table

month year  
5     2021
10    2020

I want to combine the "month" and "year" column into a proper date column.

month_year  
2021-05-01
2020-10-01

This seems to be a duplicate question for this: Concatenate in PostgreSQL

I tried both:

to_date(CONCAT(year::text, '/'::text, month::text), 'YYYY/MM') as month_year

and

to_date(CONCAT(year, '/', month), 'YYYY/MM') as month_year

but maybe the solution does not work in Redshift.

Upvotes: 0

Views: 3044

Answers (1)

John Rotenstein
John Rotenstein

Reputation: 269284

Try:

(year::text || '-' || month::text || '-01')::date

This will use ISO format (2021-11-19) for the date.

Upvotes: 2

Related Questions