【问题标题】:How can I extract from an array of json object that is saved as text?如何从保存为文本的 json 对象数组中提取?
【发布时间】:2018-12-25 19:42:31
【问题描述】:

我想从作为数组一部分的 json 中提取文本,不幸的是,它也保存为文本。

我对 postgres 数据库具有只读访问权限,该数据库通过工具 Segment 存储来自实时应用程序的值。

有一个存储为文本的列,其中包含一个 json 对象数组,结构如下:

[
  {"foo1":"bar1","foo2":"bar2"},
  {"foo3":"bar3","foo4":"bar4"}
]

再次:该列是文本,不保存为数组,如何转换然后提取 foo3 的 json 值?

【问题讨论】:

  • 看来你没有尝试。但是,如果您对运行查询的应用程序/编程语言的 Postgres 没有只读权限?
  • 将其转换为 jsonjsonb 并使用 JSON 运算符?

标签: arrays json postgresql


【解决方案1】:

这会将文本转换为 jsonb

SELECT to_jsonb('[ {"foo1":"bar1","foo2":"bar2"}, {"foo3":"bar3","foo4":"bar4"} ]'::text)

在此处阅读更多信息https://postgrespro.com/docs/postgresql/9.6/functions-json

【讨论】:

  • 谢谢,我居然发现to_jsonb(column::json)解决了问题
猜你喜欢
  • 1970-01-01
  • 2015-03-27
  • 1970-01-01
  • 2019-03-22
  • 2019-09-20
  • 2019-06-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多