Skip to content
Advertisement

Update to remove double quotes from number jsonb postgresql

I am using PostgreSQL and I am trying to run an update for jsonb.

I want “2W” to change to just the number 2.

So the query below removes the W, but leaves it as “2”.

How I would go about removing the double quotes ?

currently it looks like {“size”: “2W”} and I would like it to look like {“size”: 2}

Advertisement

Answer

You can use to_jsonb() for this:

Demo on DB Fiddle:

| jsonb_set   |
| :---------- |
| {"size": 2} |

You can replace ::int with ::numeric to handle decimal values if needed.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement