1

Hello I have column of type JSON where I store for example '{ "foo": 0 }' now I would like to write trigger which will be increment value on specific action. I have problem because I don't know how increment or set 0 value if updated value not exist. I tried to write function similar to code from here: https://stackoverflow.com/a/44563662/10999632 but It is not possible because:

ERROR:  function jsonb_set(json, unknown, jsonb) does not exist
LINE 2: SET payload = jsonb_set(payload, '{bar}', (COALESCE(payload-...
                      ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

Lukasz
  • 63
  • 8

1 Answers1

1

Apparently your column payload is defined as json, not jsonb.

You need to cast the column to jsonb in order to be able to use jsonb_set()

SET payload = jsonb_set(payload::jsonb, '{bar}', ...)