首页 > 解决方案 > PSQL 仅返回来自 jsonb_each 的值

问题描述

我正在打电话jsonb_each_text,它完全按照我的预期工作,给我回了这个:

select jsonb_each_text('{"text": "this is text", "text2": "this is text2", "f_id": "21"}') as line;
          line           
-------------------------
 (f_id,21)
 (text,"this is text")
 (text2,"this is text2")
(3 rows)

我知道我可以通过这样做轻松地只返回密钥:

select jsonb_object_keys('{"text": "this is text", "text2": "this is text2", "f_id": "21"}') as line;
 line  
-------
 f_id
 text
 text2
(3 rows)

有没有办法只能返回值?

因此,例如,我希望将其作为我的输出:

          line           
-------------------------
21
"this is text"
"this is text2"

这些值不需要是唯一的或任何东西。

我一直无法找到与jsonb_object_keysfor values only 的等价物。

标签: postgresql

解决方案


将其用作适当的集合返回函数:

select t.value
from jsonb_each_text('{"text": "this is text", "text2": "this is text2", "f_id": "21"}') as t(key, value);

推荐阅读