我需要从复杂的“ dict”(我是sql新手)中提取电子邮件
我以前看过同一主题的几篇文章(例如this one),但是似乎没有关于我的数据的文章
select au.details
from table_au au
结果:
{
"id":3526,
"contacts":[
{
"contactType":"EMAIL",
"value":"name@email.be",
"private":false
},
{
"contactType":"PHONE",
"phoneType":"PHONE",
"value":"025/6251111",
"private":false
}
]
}
我需要:
name@email.be
答案 0 :(得分:1)
select d.value -> 0 -> 'value' as Email
from json_each('{"id":3526,"contacts":[{"contactType":"EMAIL","value":"name@email.be","private":false},{"contactType":"PHONE","phoneType":"PHONE","value":"025/6251111","private":false}]}') d
where d.key::text = 'contacts'
输出:
| | email |
-------------------
|1 |"name@email.be"|
您可以在这里运行它:https://rextester.com/VHWRQ89385