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