Home > Back-end >  How to delete all data leaving a pair of values ​in hstore PostgreSQL?
How to delete all data leaving a pair of values ​in hstore PostgreSQL?

Time:06-07

I am having the data of the name column as below :

"name:en"=>"Mường Tè district", "name:ko"=>"므엉떼", "name:vi"=>"TT. Mường Tè", "name:zh"=>"芒齐市镇", "official_name"=>"Thị trấn Mường Tè", "official_name:en"=>"Muong Te Town"

name column has data type hstore in postgresql.

Is there a way to keep a pair of values ​​eg leaving only the value pair "name:vi"=>"TT.Mường Tè" ? (delete all value pairs leaving the value pair "name:vi"=>"TT.Mường Tè" ). I want to make 1 query to solve the above problem, thanks !

CodePudding user response:

The slice function does just that:

UPDATE the_table
SET name = slice(name, ARRAY['name:vi'])
  • Related