使用postgres在json中提取特定的返回字段

使用postgres在json中提取特定的返回字段,json,postgresql,Json,Postgresql,我有以下JSON: { "firstName": "John", "lastName": "Smith", "isAlive": true, "age": 27, "address": { "streetAddress": "21 2nd Street", "city": "New York", "state": "NY", "postalCode": "10021-3100" }, "phoneNumbers": [ {

我有以下JSON:

{ "firstName": "John",
  "lastName": "Smith",
  "isAlive": true,
  "age": 27,
  "address": {
    "streetAddress": "21 2nd Street",
    "city": "New York",
    "state": "NY",
    "postalCode": "10021-3100"
  },
  "phoneNumbers": [
    {
      "type": "home",
      "number": "212 555-1234"
    },
    {
      "type": "office",
      "number": "646 555-4567"
    },
    {
      "type": "mobile",
      "number": "123 456-7890"
    }
  ],
  "children": [],
  "spouse": "Maria"
}

我正在尝试获取一个数组或一个包含用户所有数字的表格,有些用户只有一个数字,有些用户有很多,有没有办法调用json中的所有“数字”

我将尝试在手机上回答这个问题,请原谅我的简短

SELECT user->>'firstName' as first_name
  , user->>'lastName' as last_name
  , phone_type
  , phone_number
FROM users_tbl
CROSS JOIN LATERAL jsonb_array_elements(user->'phoneNumbers') jarr(num_obj)
CROSS JOIN LATERAL (
  SELECT num_obj->>'type' AS phone_type
    , num_obj->>'number' AS phone_number
  ) nums

你能举一个例子说明你想要什么样的输出,也许是一个“想象中的”查询(一个不工作/不存在的查询)会给出这个输出吗?