1

This is the opposite question to this one: Creating columns in PostGIS using osm2pgsql hstore tags

First, I changed default.style to make separate 'lanes' column. Then I extracted osm database using osm2pgsql with --hstore.
Now I want to have 'lanes' column moved to tags instead of separate column. How to do this?

Will simple

UPDATE table 
SET tags->'lanes' = lanes;

work?
After this I would like to restore default.style to default (without lanes column), so that next data will be extracted in my desired form.

1

1 Answer 1

2

To add a key to an existing hstore column, you need to concatenate the current value and to add the new value. Keeping in mind that the current hstore column may be empty, you should handle this case. At last, do the update only for rows containing a lane value.

This tutorial on hstore is useful.

UPDATE mytable
SET tags = COALESCE(tags, hstore('')) || hstore('lanes', lanes) 
WHERE lanes IS NOT NULL;
2
  • What does hstore('') return? I assume this is used because of possibility of empty hstore column and I think that it creates an empty hstore?
    – kujaw
    Commented Dec 19, 2018 at 16:14
  • @kujaw exactly. If the column is currently null, it first creates an empty hstore and then concatenate the lane entry
    – JGH
    Commented Dec 19, 2018 at 16:19

Your Answer

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

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