如何在 postgresql 中解析 JSON [英] How to parse JSON in postgresql
本文介绍了如何在 postgresql 中解析 JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的数据库中有一个表,其中包含字符变化列,而该列包含 json.我需要编写一个查询,它会以某种方式将此 json 解析为单独的列.
我在
我可以轻松编写查询
SELECTID,data::json->'name' 作为名称从书;
它会导致
我也可以尝试获取不存在的列
SELECTID,data::json->'non_existant' 作为 non_existant从书;
这种情况下我会得到空结果
I have a table in my database, which contains character varying column and this column has json. I need to write a query, which will somehow parse this json into separate columns.
I found json_each function here but I can't understand how to work with it.
解决方案
I figured it out, guys
if I have a table books
I can easily write a query
SELECT
id,
data::json->'name' as name
FROM books;
And it will result in
I can also try to get non-existent column
SELECT
id,
data::json->'non_existant' as non_existant
FROM books;
And it this case I will get empty result
这篇关于如何在 postgresql 中解析 JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文