PostgreSQL 9.5:将json数据显示到表中

PostgreSQL 9.5:将json数据显示到表中,json,postgresql,Json,Postgresql,我在表表\u json中有以下记录: 表格: id doc --------------------------------------- 1 {"name":"Shaw", "address":{"line1":"L1", "line2":"L2", "zipcode":"12345"

我在表
表\u json
中有以下记录:

表格

  id        doc
  ---------------------------------------
  1 
            {"name":"Shaw",
                 "address":{"line1":"L1",
                            "line2":"L2",
                            "zipcode":"12345"
                           }
            }
  id    name    address
  --------------------------
   1    Shaw    L1,L2,12345
注:列
doc
的类型为
json
。现在我想将json数据打印成 下一个

预期产出

  id        doc
  ---------------------------------------
  1 
            {"name":"Shaw",
                 "address":{"line1":"L1",
                            "line2":"L2",
                            "zipcode":"12345"
                           }
            }
  id    name    address
  --------------------------
   1    Shaw    L1,L2,12345
在横向联接中使用
json\u each\u text()

with a_table (id, doc) as (
values
(1, '{
    "name": "Shaw", 
    "address":{
        "line1":"L1",
        "line2":"L2",
        "zipcode":"12345"
        }
    }'::json)
)
select 
    id, 
    doc->>'name' as name, 
    string_agg(value, ',') as address
from a_table, 
lateral json_each_text(doc->'address')
group by 1, 2;

 id | name |   address   
----+------+-------------
  1 | Shaw | L1,L2,12345
(1 row)
在横向联接中使用
json\u each\u text()

with a_table (id, doc) as (
values
(1, '{
    "name": "Shaw", 
    "address":{
        "line1":"L1",
        "line2":"L2",
        "zipcode":"12345"
        }
    }'::json)
)
select 
    id, 
    doc->>'name' as name, 
    string_agg(value, ',') as address
from a_table, 
lateral json_each_text(doc->'address')
group by 1, 2;

 id | name |   address   
----+------+-------------
  1 | Shaw | L1,L2,12345
(1 row)
您可以相应地浏览和使用函数。您可以相应地浏览和使用函数。