I am trying to transform my data stored in HSTORE column ('data') of Postgres.
My row values have key "entity" and value is in the array.
"entity"=>"[{'id': .............}]
I used the following code:
Alter TABLE my_table
ALTER COLUMN h_store_column TYPE jsonb
USING hstore_to_jsonb_loose(data -> 'entity');
which resulted in value as output in a new column as below:
"[{'id': .............}]"
but, with quotes "". This made it scalar in JSONB type column and doesn't let me run the query.
How can I change the value of every row in a new column named 'entity' with JSONB, without quotes?
[{'id': .............}]
SAMPLE CODE TO GENERATE SIMILAR DATA:
"key" => "[json_text_array]"
stored in hstore data type column.
When changed to JSON B type, I get {'key':'[array]'}, whereas I am after {'key': [array]} - No quotes. I tried loose functions in postgres, no help.
ERROR: function hstore_to_jsonb_loose(text) does not exist- jjanes{'id': …}is not valid JSON.{"id": …}would be. If your value looked like that, you could use(data -> 'entity')::jsonb. (Notice thathstore_to_jsonb_looseis absolutely unnecessary as-> 'entity'already accesses the string value in the hstore). - Bergi