json - 在 Postgresql 10.8 中,如何将 char 类型字段更改为 json 类型,然后获取 json 字符串中的数字?
问题描述
Postgresql 版本是 10.8
这是sql:
update nt_order set common_field='{"bind_channel":"company","bind_status":"binding","version":1234}' where id=1 and (common_field is null or (common_field::json->>'version')::bigint is null or (common_field::json->>'version')::bigint < 12345);
执行此sql时,出现错误:
ERROR: invalid input syntax for type json
DETAIL: The input string ended unexpectedly.
CONTEXT: JSON data, line 1
如果Postgresql版本是9.5,执行上面的sql没有问题。
那么如何在 Postgresql 10.8 中解决这个问题呢?
解决方案
根据详细信息和上下文,我会说您的字段中有某行的空字符串。这不能转换为 json,即使在 9.5 版本中也不行,因此您的 9.5 服务器中必须有不同的数据。
大概你想对 '' 做同样的事情,就像你对 NULL 做的一样,所以只需将该测试添加到你的 OR 列表中。
推荐阅读
- azure - 如何更新和重新部署 ARM 模板
- python - 使用正则表达式的美丽汤提取时间
- python - 为什么我会收到这个意外的关键字参数 TypeError?
- javascript - 如何使用 HTML 获取用户输入以在 JS 中处理?
- python - 如何修复此代码中的错误?
- java - 如何在给定时间(例如上午 7:15)安排任务
- excel - COUNTIF 取决于单元格格式和输入类型?
- swift - MapKit - 找到路线但未显示
- kubernetes-helm - Helm:如何使用“.Files.Get”将 json 导入配置映射
- python - 如何在 request.post 方法中使用 json 和 files 参数上传文件