Postgresql – Remove the deeper jsonb element in Postgres

postgresqlpostgresql-9.6

[ 
   { 
      "type":"test.added",
      "values":[ 
         { 
            "field":"field1",
            "value":"fieldValue1"
         },
         { 
            "field":"field2",
            "value":"fieldValue2"
         }
      ]
   }
]

I want to remove the 'field1' object pair from the JSON in postgres

Here is what I have tried so far,

  • updatedJson -> 0 ->> 'values' - '"field1"'
  • i tried using the #- Delete the field or element with specified path
    (for JSON arrays, negative integers count from the end)

Both steps didn't help me. I am new to Postgres. Is there any way like getting the path and deleting it. I am using jsonb. PostgreSQL version: 9.6.
Kindly help

Best Answer

i tried using the #-

What specifically did you try?

Using #- works for me, specifically updatedJson #- '{0,values,0}'