I have a column which had json schema value
{
"red": false, -> would like switch to true
"blue": false,
"yellow": true
}
how should I switch the boolean value under the specific filed ?
(assume I do not know the original value in this field)
I try:
UPDATE table
SET column = jsonb_set(column, '{red}', NOT (column->>red)::jsonb)
WHERE id = 1;
but I got
argument of NOT must be type boolean, not type jsonb
seems like it could not do the NOT
operate in jsonb
but after I transfer jsonb
type to boolean
type, I could not use that in jsonb_set
method
so how should I switch the boolean value under the specific filed ?
!!! (assume I do not know the original value in this field)
Update:
I found a solution for this ->
UPDATE table
SET column = jsonb_set(
column,
'{red}',
to_jsonb(NOT((column->>'red')::jsonb)::BOOLEAN))
WHERE id = '1';
but this solution is not pretty...