By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE
INSERT 0 9
| id | start_date | end_date | objekt_id | person_id | row_id | last_person | next_person | last_person_partition | next_person_partition | real_last_person | real_next_person |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 2011-10-01 | 2015-10-31 | 5156 | 18268 | 1 | null | null | 0 | 3 | null | 18268 |
| 2 | 2015-11-01 | 2018-04-30 | 5156 | null | 2 | 18268 | 18268 | 1 | 3 | 18268 | 18268 |
| 3 | 2018-05-01 | 2018-05-02 | 5156 | 18268 | 3 | null | 18269 | 1 | 2 | 18268 | 18269 |
| 4 | 2018-05-03 | 2021-03-31 | 5156 | 18269 | 4 | 18268 | null | 2 | 1 | 18268 | 18270 |
| 5 | 2021-04-01 | 2021-04-02 | 5156 | null | 5 | 18269 | null | 3 | 1 | 18269 | 18270 |
| 6 | 2021-04-03 | 2021-05-15 | 5156 | null | 6 | null | 18270 | 3 | 1 | 18269 | 18270 |
| 7 | 2021-05-16 | 2100-01-01 | 5156 | 18270 | 7 | null | null | 3 | 0 | 18269 | null |
| 8 | 2021-03-14 | 2021-05-15 | 5160 | 18270 | 1 | null | 18271 | 0 | 1 | null | 18271 |
| 9 | 2021-05-16 | 2100-01-01 | 5160 | 18271 | 2 | 18270 | null | 1 | 0 | 18270 | null |
SELECT 9