0

I'm using PostgreSQL,

The task will be like this

UPDATE user SET  height= { 'unit': 'Cms', 'value': 170 }

ERROR:  syntax error at or near "{"

so is there a way to do UPDATE query that just adds a new element or alters the existing element/node in array/json obejct types in PostgreSQL?

Felix Lemke
  • 6,189
  • 3
  • 40
  • 67
Rahul Dapke
  • 345
  • 6
  • 19
  • Does this answer your question? [How to perform update operations on columns of type JSONB in Postgres 9.4](https://stackoverflow.com/questions/26703476/how-to-perform-update-operations-on-columns-of-type-jsonb-in-postgres-9-4) – BENARD Patrick Dec 12 '19 at 11:52

2 Answers2

0

try this

 UPDATE user SET height = '{"unit": "Cms", "value": 150}'::jsonb
0

the error you are getting is because you should provide it as a string

update user set height = '{"unit": "Cms", "value": 150}'::jsonb
Mustafa Kunwa
  • 821
  • 1
  • 9
  • 19