提取 postgresql jsonb 对象的所有值

Meh*_*avi 2 postgresql jsonb

我有一个 postgresql 表 t1,id 整数,数据 jsonb

   id    |   data
--------------------
    1    | {"1":{"11":11},"2":{"12":12}}
Run Code Online (Sandbox Code Playgroud)

我需要一个函数来提取这样的单独行中的所有键/值

   key   |   values
----------------------
    1    |  {"11":11}
    2    |  {"12":12}
Run Code Online (Sandbox Code Playgroud)

在“hstore”数据类型中,有“hvals”函数,这样做
但在 jsonb 中我没有找到类似的函数

a_h*_*ame 5

你正在寻找 jsonb_each

with t1 (id, data) as (
  values (1, '{"1":{"11":11},"2":{"12":12}}'::jsonb)
)
select t.*
from t1, jsonb_each(data) as t(k,v)
Run Code Online (Sandbox Code Playgroud)

返回:

k | v         
--+-----------
1 | {"11": 11}
2 | {"12": 12}
Run Code Online (Sandbox Code Playgroud)