首页 > 解决方案 > 在物化视图中保存 jsonb_each 的输出

问题描述

我在 PG 12 中有一个表“t”-

Id int

Col1 character varying

Data_col jsonb

Data_col 如下所示:

{key1:值 1,key2:值 2,key3:值 3....}

我可以使用以下选择以拖曳形式获取键和值

Select t.id, t.col1, x.key, x.value
From t, jsonb_each_text(t.data_col) x

我想知道是否有办法将上述选择的输出存储到物化视图中?我试过了-

Create materialized view t_mv
As
Select t.id, t.col1, x.key, x.value
From t, jsonb_each_text(t.data_col) x;

但我得到一个错误

error cannot call jsonb_each on a non-object

有任何想法吗?

谢谢

标签: jsonpostgresql

解决方案


你的尝试应该有效。但是,您的查询中的列名不匹配。查询使用 col2,但表是用 col1 定义的。


推荐阅读