如何将 jsonb 中的时间戳更新为函数 now() 的值?
我尝试像这样做smt
UPDATE test
SET column = jsonb_set(column,'{time}',to_char(now(),'some date format'),true)
Run Code Online (Sandbox Code Playgroud)
我遇到了类似的错误
'jsonb_set(json,unknown,text,bool) is not available'
Run Code Online (Sandbox Code Playgroud)
我认为错误的原因是 now() 的值不是单引号,因为这个查询正在工作
UPDATE test
SET column = jsonb_set(column,'{time}','date with the same date format ',true)
Run Code Online (Sandbox Code Playgroud)
有什么解决办法吗?
jsonb_set(json,unknown,text,bool) is not available
PostgreSQL 找不到具有此签名的函数。根据文档,签名是jsonb_set(jsonb, text[], jsonb, boolean).
to_char()正在返回text您需要的位置jsonb,并且强制转换应该可以解决问题:
jsonb_set(column, '{time}', to_char(now(),'\"some date format\"')::jsonb, true)
Run Code Online (Sandbox Code Playgroud)
(请记住,::jsonb需要有效的 JSON 作为输入,例如"围绕字符串。)
| 归档时间: |
|
| 查看次数: |
4699 次 |
| 最近记录: |