微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在 postgres 9.6 中从 jsonb 中提取整数数组

如何解决在 postgres 9.6 中从 jsonb 中提取整数数组

我目前有一个查询可以在 Postgres 13 上正常运行,但在 9.6 上不能正常运行。如下:

select specs.upc,specs.price,specs.edlp,specs.productlinegroups
              from customer_products,jsonb_to_recordset(customer_products.products) as specs(upc varchar,edlp decimal,price decimal,productlinegroups int[])
              where customer_id = 821880
             and array[12,34] && productlinegroups

customer_products 表

field_name 类型
customer_id 整数
产​​品 jsonb

产品数据示例:

[{"upc": "00338001205","edlp": 3074,"price": 3819,"productlinegroups": [428,31,300,523,537,573]},{"upc": "00338002202","edlp": 6398,"price": 4041,"productlinegroups": [31,428,573]}]

问题在于 productlinegroups int[] 转换。

我一直在努力寻找一种适用于 Postgres 9.6 的解决方案,并且一直在修补:

select specs.upc,jsonb_array_elements_text(productlinegroups)
               from customer_products,productlinegroups jsonb )
               where customer_id = 821880
               and array[12,34] && productlinegroups

但是,我需要聚合该字段,并且我认为我需要一个外部查询来分组。

这是一个更大查询的一部分,性能一个问题。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。