skip to Main Content

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


  1. 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);
    
    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search