更新jsonb postgres中的时间戳

时间:2018-05-24 04:50:50

标签: postgresql relational-database

如何将jsonb中的时间戳更新为函数now()的值?

我试着像这样做smt

    UPDATE test
    SET column = jsonb_set(column,'{time}',to_char(now(),'some date format'),true)

我收到了像

这样的错误
    'jsonb_set(json,unknown,text,bool) is not available' 

我认为错误的原因是now()的值不是单引号,因为这个查询正常工作

    UPDATE test
    SET column = jsonb_set(column,'{time}','date with the same date format ',true)

有没有解决方案?

1 个答案:

答案 0 :(得分:1)

  

jsonb_set(json,unknown,text,bool) is not available

PostgreSQL无法找到具有此签名的函数。根据{{​​3}},签名为jsonb_set(jsonb, text[], jsonb, boolean)

to_char()正在返回text您需要jsonb的位置,而演员应该可以做到这一点:

jsonb_set(column, '{time}', to_char(now(),'some date format')::jsonb, true)

(请注意,::jsonb需要有效的JSON作为输入,例如围绕字符串"。)

相关问题