问题描述
列类型jsonb。
此处json:
"weight": {
"qty": 1.8,"unit": {
"name": "gram","title": {
"en": "g"
}
...
"options": [{
{
"name": "weight","title": {
"en": "Weight"
},"value": {
"name": "1-8g",}
仅当wights.qty
(浮动)与options[value.name]
(文本)不相等时,我才需要显示。
首先,我将wights.qty
转换为文本并添加符号“ g ”。同时用“。”替换“-”。只有在那之后,我才进行比较。
此示例绝不能显示,因为其中有相等的数字(1.8g = 1.8g)
此处查询:
SELECT
concat((p.data #>>'{weight,qty}')::numeric::text,'g') AS weight_qty,replace((select *
from jsonb_array_elements(p.data -> 'options') AS options_array
where
options_array ->> 'name' = 'weight'
limit 1) #>>'{value,name}','-','.') as options_weight
from product p
where not exists
(select *
from jsonb_array_elements(p.data -> 'options') AS options_array
where
options_array ->> 'name' = 'weight'
and
options_array -> 'value' ->> replace('name','.') = concat((p.data #>>'{weight,'g') )
order by id desc
但是此记录显示在结果中
您可以看到第二和第三条记录是正确的。但是首先不是。不能显示第一条记录。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)