sql - 在 postgresql 中展平包含字符串和嵌套数组的 jsonb 对象
问题描述
我在表中的数据为:
column |datatype
-----------|--------
id | integer
name | text
phone | text
education | jsonb
示例数据为:
id | name | phone | data |
------|----------|-----------|----------|
1 |Test User |78545254 | [[{"label": "Type", "value": "Graduate"}, {"From", "value": "01-04-2015"}, {"label": "To", "value": "21-04-2016"}],[{"label": "Type", "value": "Post Graduate"}, {"From", "value": "01-04-2015"}, {"label": "To", "value": "21-04-2016"}]] |
2 |Test Usr |78545254 | [[{"label": "Type", "value": "Graduate"}, {"From", "value": "01-04-2015"}, {"label": "To", "value": "21-04-2016"}]] |
我想做一个查询,它可以给我输出:
id | label | value |
---|--------------------|-----------------|
1 | name | Test User |
1 | phone | 78545254 |
1 | education_Type_1 | Graduation |
1 | education_From_1 | 01-04-2015 |
1 | education_To_1 | 21-04-2016 |
1 | education_Type_2 | Post Graduation |
1 | education_From_2 | 01-04-2015 |
1 | education_To_2 | 21-04-2016 |
2 | name | Test Usr |
2 | phone | 78545254 |
2 | education_Type_1 | Graduation |
2 | education_From_1 | 01-04-2015 |
2 | education_To_1 | 21-04-2016 |
谁能帮我建立这样的查询?
解决方案
推荐阅读
- java - Websphere 8.5 应用程序服务器无法将消息发送到响应队列
- java - 在 setScreen(new Screen2()) 之后无法停止渲染前一个 Screen1();
- sdl-2 - 在 Windows 10 中安装 Common Lisp Sketch 时出现问题
- c++ - 如何在 UML 类图中表示纯虚函数?
- swift - 使用 reloadData() 使滚动条在 UITableView 上始终可见
- docker - Docker 增加容器内存
- scala - 处理将数据帧保存到 Hbase-spark scala 的代码时出错
- python - 在 requests.post 之后返回请求上下文
- apache-camel - 骆驼豆生命周期策略?
- java - 具有 MayToMany 关系的 Spring Data JPA 规范