Here is my problem: I had a polygon layer with an index which looks like this:
id, population
100, 26
200, 12
300, 45
...
I edited the polygon layer and divided some of the polygons into smaller polygons (approximately 3-7 subpolygons). I already took care of having my data splitted between subzones (according to population density). So now I have this:
id, population
100, 22
100, 1
100, 3
200, 6
200, 6
I would like to create a new index that reflects the old one. For instance:
oldId, newId, population
100, 100, 22
100, 101, 1
100, 102, 3
200, 200, 6
200, 201, 6
Things I tried: Defining a sequence:
DROP SEQUENCE IF EXISTS increment_id;
CREATE TEMP SEQUENCE increment_id INCREMENT BY 1 MINVALUE 0;
SELECT
id,
id+nextval('increment_id') AS new_id
FROM polygon_mapping WHERE id = 100;
THis works well for a single id to rename (the WHERE clause), but I don't know how to restart the sequence for every id.
I made some thinking around using the 'lag' function to compare current id with previous id. But I don't manage make it work.
Any suggestions? Thank you
ps: I went through Reset auto increment counter in postgres where they reset the SEQUENCE but I don't manage to make it work in a SELECT clause.