0

Hi i have this structure in my column jsonb in postgres

{

    "cronograma_actividades": {
      "section_template_id": 5,
      "ciclos": [
        {
          "ciclo_verano": {
            "nro_semanas_max": 9,
            "programas": [
              {
                "pregrado": {
                  "modalidades": [
                    {
                      "type": "presencial",
                      "codigo_formula": "FOR2234",
                      "unidades": [
                        {
                          "nro": 1,
                          "titulo": "Unidad aprendi",
                          "logro": "Logro de una unidad es texto",
                          "semanas": [

                                  ]
                                },
                                {}
                              ]
                            },


  ]
}

So how I can update the field codigo_formula with postgres this column is a jsonb type I find the json_object_set_path , but i dont know how acces to deep tree

Regards

HalleyRios
  • 602
  • 1
  • 4
  • 18

1 Answers1

0

Assuming the column that contains your jsonb is called "testcol", you can do this:

update t_test set testcol = jsonb_set(testcol, '{cronograma_actividades,ciclos,0,ciclo_verano,programas,0,pregrado,modalidades,0}', jsonb('{"cordigo_formula":"new value"}'), false);

The 0 values indicate the position in your array. There's actually an impressive post about json(b) in postgresql that you might want to read right here.

Heiko Jakubzik
  • 409
  • 5
  • 12