【发布时间】:2021-08-14 23:54:15
【问题描述】:
我之前的问题已经得到解答,感谢@Erwin Brandstetter 的帮助:
Query individual values in a nested json record
我有后续:
Aurora Postgres - PostgreSQL 13.1。我的jsonb 列值如下所示:
'{
"usertype": [
{
"type": "staff",
"status": "active",
"permissions": {
"1": "add user",
"2": "add account"
}
},
{
"type": "customer",
"status": "suspended",
"permissions": {
"1": "add",
"2": "edit",
"3": "view",
"4": "all"
}
}
]
}'
我想生成一个表格样式的输出,其中每个权限项都显示为一列。如果不为空,则应显示该值,否则为空。
type | status | perm1 | perm2 | perm3 | perm4 | perm5 | perm6
----------+-----------+---------+------------+-------+-------+-------+-------
staff | active | adduser | addaccount | null | null | null | null
customer | suspended | add | edit | view | all | null | null
换句话说,我想要一种方法来找出最大权限计数并在选择查询中显示那么多列。
【问题讨论】:
-
请让这个问题的读者更容易理解,并在 this 问题中也包含一个minimal reproducible example,即使您的上一个问题已经有一个。
-
粘性位说了什么。另外,您仍然没有声明您的 Postgres 版本。
-
用版本和示例详细信息更新了原始问题
标签: sql json postgresql