0

I'm trying to add a property to an existing jsonb column (column "data").

I want have my jsonb document to log like this

{
  // ... existing properties
  "Filed": false // new property
}

I tried

UPDATE "doc" SET "data" = jsonb_set("data"::jsonb, 'Filed', false, true)

I get this error:

[42883] ERROR: function jsonb_set(jsonb, unknown, boolean, boolean) does not exist 
Hint: No function matches the given name and argument types. 
You might need to add explicit type casts. Position: 46

2 Answers 2

1

It should be

jsonb_set("data"::jsonb, '{Filed}', 'false', TRUE)

The second parameter is an array denoting the path to the appropriate key, and 'false' is the string representation of a JSON boolean.

Sign up to request clarification or add additional context in comments.

Comments

0

Better use the || operator.

UPDATE "doc" SET "data" = "data" || '{"Filed": false}';

This one is equivalent but more suitable for parameterization:

UPDATE "doc" SET "data" = "data" || jsonb_build_object('Filed', false);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.