以JSON格式数据到PostgreSQL中的表格
在PostgreSQL中需要帮助JSON的帮助。我想要此查询
从面板中选择数据
返回:
Data
1 [{"type": "opened","user": "1"},{"type": "added","user":"2"}]
2 [{"type": "added","user": "3"}]
3 [{"type": "opened","user": "3"},{"type": "opened","user":"2"}]
返回表:
type user
opened 1
added 2
added 3
opened 3
opened 2
我不太了解如何表示[和{和{{。我将感谢任何指导,因为我还没有找到这个特定的例子
Need help with json deserialization in postgresql. I would like this query
select data from panel
that returns:
Data
1 [{"type": "opened","user": "1"},{"type": "added","user":"2"}]
2 [{"type": "added","user": "3"}]
3 [{"type": "opened","user": "3"},{"type": "opened","user":"2"}]
instead returned a table:
type user
opened 1
added 2
added 3
opened 3
opened 2
I don't quite understand how to represent the empty space between [ and {. I would appreciate any guidance as I have not found this particular example
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
JSONB_ARRAY_ELEMENTS
将阵列转换为行,然后提取键:假设使用数据类型
JSONB
(是什么)假设data
是定义的应该是)。如果不是,则必须施放它:data :: JSONB
Use
jsonb_array_elements
to turn the arrays in to rows, then extract the keys:This assumes that
data
is defined with the data typejsonb
(which it should be). If it's not, you have to cast it:data::jsonb