错误的原因是什么是从对象中提取元素的原因。
我需要创建一些请求女巫,如果它为null,则会添加一个JSON对象:
{
"json_object_1": [
{
"x": 0,
"y": 0,
"value": 0
}
],
*a new object must be added here*
}
如果它不是null,则将键值对添加到嵌套对象中:
{
"json_object_1": [
{
"x": 0,
"y": 0,
"r": 0
}
],
"json_object_2":[
{
"x": 0,
"x":0,
*new key-value pair*
}
]
}
我写了我的请求,但仅在第一次尝试后起作用。之后,我会收到一个错误:SQL错误[22023]:错误:无法从对象中提取元素。此错误的原因是什么?我该如何解决?
update table
set json_column = (
case
when json_column = json_column - 'json_object' then
json_column - 'json_object' || jsonb_build_object('json_object', jsonb_build_object('value', 3))
else jsonb_set(
json_column,
'{json_object}',
(select jsonb_agg(elem ||'{"value": 3}')
from jsonb_array_elements(json_column->'json_object') AS elem))
end
)
where json_column is not null;
I need to create some request witch will add an json object if it is null:
{
"json_object_1": [
{
"x": 0,
"y": 0,
"value": 0
}
],
*a new object must be added here*
}
or add a key-value pair into a nested object if it is not null:
{
"json_object_1": [
{
"x": 0,
"y": 0,
"r": 0
}
],
"json_object_2":[
{
"x": 0,
"x":0,
*new key-value pair*
}
]
}
I wrote my request but it works only after the first try. After that I get an error: SQL Error [22023]: ERROR: cannot extract elements from an object. What is the reason of this error and how can I fix it?
update table
set json_column = (
case
when json_column = json_column - 'json_object' then
json_column - 'json_object' || jsonb_build_object('json_object', jsonb_build_object('value', 3))
else jsonb_set(
json_column,
'{json_object}',
(select jsonb_agg(elem ||'{"value": 3}')
from jsonb_array_elements(json_column->'json_object') AS elem))
end
)
where json_column is not null;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论