How can I update an hstore[] field?
-
29-09-2020 - |
Question
I have table products
, in which there is an hstore array field countries_of_origin
.
So a product that is assembled from multiple products might have multiple countries of origin:
[
{ "country" => "USA" },
{ "country" => "MEX" }
]
My only issue is, I have no idea whatsoever on how to write a SQL update
. Our developers interact with the table via an ORM. But I sometimes have to do a mass update for expediency's sake, and I don't know to do it!
Thanks for any help you can offer.
Solution
Look at the examples for hstore
in the PostgreSQL documentation.
UPDATE tab SET h = h || ARRAY['b => 2'::hstore,'c => 3'::hstore];
Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange