0

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'

thanks

asked Aug 31, 2016 at 21:39
3
  • 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. Commented Aug 31, 2016 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 Commented Sep 1, 2016 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. Commented Sep 1, 2016 at 8:42

2 Answers 2

1

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.

answered Sep 1, 2016 at 8:27
1
  • i have try this and works : select * from topdog where tags = '"created_by"=>"JOSM"' thanks Commented Sep 1, 2016 at 20:33
0

use

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)

answered Sep 1, 2016 at 8:32

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.