使用PostgreSQL搜索所有JSON字段

使用PostgreSQL搜索所有JSON字段,sql,json,postgresql,Sql,Json,Postgresql,如何查询JSON字段以在JSON的所有字段中搜索 桌子 我想查询JSON的每个字段,因为我正在编写一个全局搜索函数,例如,我需要返回JSON中包含“toto”的每一行 我在SQLServer2016中使用OPEN_JSON函数成功地做到了这一点 这是我的密码 SELECT DISTINCT * FROM ObjectsTable CROSS APPLY OPENJSON([JSON]) as tbValues WHERE tbValues.value like '%toto%' 我需要在Pos

如何查询JSON字段以在JSON的所有字段中搜索

桌子

我想查询JSON的每个字段,因为我正在编写一个全局搜索函数,例如,我需要返回JSON中包含“toto”的每一行

我在SQLServer2016中使用OPEN_JSON函数成功地做到了这一点

这是我的密码

SELECT DISTINCT *
FROM ObjectsTable
CROSS APPLY OPENJSON([JSON]) as tbValues
WHERE tbValues.value like '%toto%'

我需要在Postgres中做同样的事情。

在Postgres中基本相同,但在SQL标准和Postgres中,
交叉应用
交叉连接横向

select o.id, t.*
from objectstable o
  cross join lateral json_each_text(o.json) as t(k,val)
where t.val like '%toto%'

在Postgres中基本相同,但在SQL标准和Postgres中,
cross-apply
cross-join-lateral

select o.id, t.*
from objectstable o
  cross join lateral json_each_text(o.json) as t(k,val)
where t.val like '%toto%'