Greg
Greg

Reputation: 1

updating a JSONb field in a postgres

I have a table world with a field v (jsonb) and workflow_id (int). I want to run the command: UPDATE world SET v = {'a': 1} WHERE workflow_id = 84; This gives me a syntax error - I've tried putting quotation marks around the json value in all of the different combinbations I can think of but nothing works. If I try "{'a':1}", it tells me that column "{'a':1}" does not exist.

Any help would be appreciated.

Upvotes: 0

Views: 1234

Answers (1)

Sagar Koshti
Sagar Koshti

Reputation: 428

Try

UPDATE world SET v = '{"a": 1}::jsonb' WHERE workflow_id = 84;

cause you need to cast your text to jsonb datatype.

else you can also try

UPDATE world SET v = CAST('{"a": 1}' AS JSONB) WHERE workflow_id = 84;

Upvotes: 2

Related Questions