小编Che*_*izz的帖子

Postgresql json列查看

我有一张看起来像这样的桌子

id |   json_column
---+------------
 1 | {"text1":"a", "text2":"b", "text3":"c", ....}
 2 | {"text1":"b", "text2":"c", ....}
Run Code Online (Sandbox Code Playgroud)

我希望它像这样

text1 | text2 | text3 | ....
a     | b     | c     | ....
b     | c     | d     | ....
Run Code Online (Sandbox Code Playgroud)

我发现得到这个结果的一个变体是使用 json_populate_record() 并创建一个新类型 x as (text1 text, text2 text, text3 text,....) 所以我可以执行

select (json_populate_record(null::x, json_column)).* from table
Run Code Online (Sandbox Code Playgroud)

有没有另一种方法可以在不创建上述类型的情况下做到这一点?所有新列都可以有类型文本,那么可能有快捷方式吗?

我的问题是我在 aaaa_bbbb_cccc_d 形式的一个 json 字段中有 50 个键,因此手动为此创建一种类型会花费很多时间

我正在使用 9.5.4

postgresql json postgresql-9.5

7
推荐指数
1
解决办法
6414
查看次数

标签 统计

json ×1

postgresql ×1

postgresql-9.5 ×1