【问题标题】:Postgres conver json string to date formatPostgres 将 json 字符串转换为日期格式
【发布时间】:2022-01-11 20:56:39
【问题描述】:

我正在使用以下方法从 json 字段中提取结束日期: data->>'closeDate' as PortalCloseDate 但是这会返回一个字符串,我正在尝试将其转换为日期格式。字符串中的日期格式为 YYYY-MM-DD,所以我尝试了 (data->>'closeDate')::date,但收到错误消息:“错误:类型日期的输入语法无效:“‎2020-‎12-‎09”” 任何帮助表示赞赏,谢谢!

【问题讨论】:

    标签: json postgresql date type-conversion


    【解决方案1】:

    尝试暴力破解清理字符串并将其强制转换为日期:

    select 
       cast(replace(cast(data->>'closeDate' as varchar), '"','') as date) as "closeDate" 
    from table
    

    【讨论】:

    • 当我尝试它仍然返回错误:错误:类型日期的输入语法无效:“‎2020-‎12-‎09”
    猜你喜欢
    • 2013-12-28
    • 1970-01-01
    • 2014-01-18
    • 2019-10-13
    相关资源
    最近更新 更多