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.

1 Answer 1

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}', ...)
Sign up to request clarification or add additional context in comments.

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.