Home > Mobile >  PostgreSQL: update json issue
PostgreSQL: update json issue

Time:03-28

Table has a json-column named "stats" with the following value: {"countValue":0}

I'm trying to update this value by:

 UPDATE my_table
 SET stats = jsonb_set(stats, '{countValue}', 1);

But receive the following error:

 No function matches the given name and argument types. You might need to add explicit type casts.

I tried to fix the problem, by applying explicit type cast for countValue (countValue::text), but with the same result.

What am I doing wrong?

CodePudding user response:

You might need to use jsonb type on '1' instead of integer from jsonb_set function signature

jsonb_set(target jsonb, path text[], new_value jsonb [, create_missing boolean])

UPDATE my_table
SET stats = jsonb_set(stats, '{countValue}', '1');

sqlfiddle

  • Related