how to select just red area i have a data which is in Hstore form so i want to select a specific key and value from data and then delete them, as i use this query it is find all rows which this key and value exist on it but i want those rows which is only involve this key and value not all

select * from topdog where tags @> 'created_by=>JOSM'


  • I have read your question several times but still don't understand what you want to achieve exactly. Can you clarify? And provide your Postgres version and table definition. – Erwin Brandstetter Aug 31 '16 at 23:34
  • i am using Postgres 9.3 the question is "i want to delete those rows which has just tags("created_by"=>''JOSM'). when i use this query select * from topdog where tags @> 'created_by=>JOSM' the result is : 16382115;""name"=>"Vazební věznice Brno", "amenity"=>"prison", "created_by"=>"JOSM""; 18008930;""created_by"=>"JOSM""; 21288991;""created_by"=>"JOSM""; 8166183;""source"=>"uhul:ortofoto", "highway"=>"footway", "created_by"=>"JOSM""; but i want to selected and then delete only rows with tags ""created_by"=>"JOSM"" not all rows – jack Sep 1 '16 at 7:55
  • I hope you don't want to do a OSM mechanical edit to remove those created_by tags; this is discouraged. See wiki.openstreetmap.org/wiki/Key:created_by , specially You should not remove the created_by tag on objects you are not otherwise modifying. If we wanted to remove them in bulk we'd do it some other way. – til_b Sep 1 '16 at 8:42

Seems that you should use the = (equality) operator instead of @>(containment).

It will filter only the exact rows and you could use them in a delta statment.

  • i have try this and works : select * from topdog where tags = '"created_by"=>"JOSM"' thanks – jack Sep 1 '16 at 20:33


select * from <table> where tags->'created_by' = 'JOSM' and len(akeys("tags"))=1

That way you select those that have the created_by tag and only one hstore key.

I don't know if len() is the correct function to use for "array element count" (maybe it's array_length()).

See the hstore doc at https://www.postgresql.org/docs/9.1/static/hstore.html .

(Disclaimer: I dont have a hstore enabled db to test with)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.