假设我有一个 json 列字段,如下所示:
{phone: 5555555555, address: "55 awesome street", hair_color: "green"}
我想做的是更新所有存在 json key phone 的条目,结果是 number 类型的字符串。
我所拥有的是:
SELECT *
FROM parent_object
WHERE (fields->'phone') IS NOT NULL;
不幸的是,这仍然返回值 where phone:null
。我猜 JSONnull
不等同于 SQL NULL
。
我该怎么做 1) 如何排除 JSON 空值
AND (fields->'phone') <> null
产生
LINE 4: ...phone') IS NOT NULL AND (fields->'phone') <> 'null';
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
2)检查那个键的值的类型,这个伪代码(type_of (fields->'phone') == Integer)
但是在工作的PGSQL中。
3)修改此以更新列
UPDATE parent_object
SET fields.phone = to_char(fields.phone)
WHERE query defined above