Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(DB): Add new v_abgegrenzte_interessenbindung view #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

knutwannheden
Copy link
Contributor

Adds a new database view v_abgegrenzte_interessenbindung which in contrast to the interessebindung table has the columns von_effektiv and bis_effektiv to represent the start and end date for the validity period (as opposed to von and bis). These dates are never null and when the end date is yet unknown (open-ended) the bis_effektiv will be represented by the date 9999-12-31.

The value for von_effektiv will correspond to von when given and otherwise to freigabe_datum or parlamentarier.im_rat_seit, in case the interessebindung row was created as part of the initial research of the politician.

Also note that in case a politician was elected for two non-consecutive periods of time (cf. parlamentarier.ratsunterbruch_von and parlamentarier.ratsunterbruch_bis), then the same interessebindung object may (depending on von and bis) end up being represented by multiple rows in this view (both with the same value for interessebindung_id).

Related: #18

db_views.sql Show resolved Hide resolved
db_views.sql Show resolved Hide resolved
db_views.sql Show resolved Hide resolved
Adds a new database view `v_abgegrenzte_interessenbindung` which in contrast to the `interessebindung` table has the columns `von_effektiv` and `bis_effektiv` to represent the start and end date for the validity period (as opposed to `von` and `bis`). These dates are never `null` and when the end date is yet unknown (open-ended) the `bis_effektiv` will be represented by the date 9999-12-31.

The value for `von_effektiv` will correspond to `von` when given and otherwise to `freigabe_datum` or `parlamentarier.im_rat_seit`, in case the `interessebindung` row was created as part of the initial research of the politician.

Also note that in case a politician was elected for two non-consecutive periods of time (cf. `parlamentarier.ratsunterbruch_von` and `parlamentarier.ratsunterbruch_bis`), then the same `interessebindung` object may (depending on `von` and `bis`) end up being represented by multiple rows in this view (both with the same value for `interessebindung_id`).
join parlamentarier_amtszeit pa on pa.id = i.parlamentarier_id
join organisation o on i.organisation_id = o.id
and von_effektiv <= coalesce(bis, date '9999-12-31')
and coalesce(bis_effektiv, date '9999-12-31') > coalesce(von, i.freigabe_datum)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wie du siehst habe ich hier und da das Datum 9999-12-31 verwendet. Dies erleichtert es Abfragen gegen diese View zu schreiben, da NULL nicht hantiert werden muss. Falls das ein "Stilbruch" ist, können wir das aber auch gerne wieder entfernen oder mit einem anderen Datum ersetzen. (Irgendwo habe ich 2038-01-01 gesehen, das ist aber schon "relativ bald".)

Du hast vermutlich auch gesehen, dass ich Date Literals so schreibe: date '9999-12-31'. Dies sollte portabel sein, aber wenn es dir lieber ist, schreibe ich es auf STR_TO_DATE('31.12.9999','%d.%m.%Y') um.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants