postgresql : **ERROR: path element at position 1 is not an integer:**
-
04-03-2021 - |
Domanda
I am trying to update a field value in jsonb column with text value present in another column but getting some syntax errors; not getting any solution.
i am trying to swap values of OutgoingVertexid & IncomingVertexId in below JSONB
'[
{
"Edgeid":10,
"Weight":100,
"Active":1,
"OutgoingVertexid":"",
"IncomingVertexid":"G",
"EdgeColor":"Black"
}
]
'
so used below code by putting all values OutgoingVertexid & IncomingVertexid value in temp table.
UPDATE temp_table
SET
owner_property = CASE
WHEN owner_outgoing_edge IS NOT NULL
THEN jsonb_set(owner_property, '{OutgoingVertexid}', '""')
ELSE
jsonb_set(owner_property, '{OutgoingVertexid}', ''||owner_incoming_edge::jsonb||'')
END;
but getting below error:
ERROR: path element at position 1 is not an integer:
Thanks in Advance
Soluzione
Your json value is an array, not a single value. So you need to pick the array element you want to change by including the index in the array you pass to jsonb_set()
UPDATE temp_table
SET owner_property = CASE
WHEN owner_outgoing_edge IS NOT NULL
THEN jsonb_set(owner_property, '{0, OutgoingVertexid}', '""')
ELSE
jsonb_set(owner_property, '{0, OutgoingVertexid}', to_jsonb(owner_incoming_edge))
END
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a dba.stackexchange