【问题标题】:Combine separate month and year in Redshift在 Redshift 中合并单独的月份和年份
【发布时间】:2021-11-19 08:44:06
【问题描述】:

base_table

month year  
5     2021
10    2020

我想将“月”和“年”列组合成一个合适的日期列。

month_year  
2021-05-01
2020-10-01

这似乎是一个重复的问题: Concatenate in PostgreSQL

我都试过了:

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

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

但也许该解决方案在 Redshift 中不起作用。

【问题讨论】:

  • 无效的操作:函数concat(字符变化,字符变化,字符变化)不存在;
  • make_date 似乎不适用于 PostGreSQL 8.0 (Redshift)

标签: sql amazon-web-services amazon-redshift


【解决方案1】:

试试:

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

这将使用 ISO 格式 (2021-11-19) 作为日期。

【讨论】:

    猜你喜欢
    • 2019-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-08
    • 2016-10-30
    相关资源
    最近更新 更多