From 645ce32f11ecd10a0ebff545351d97a7ed9a67b3 Mon Sep 17 00:00:00 2001 From: Falk Mielke Date: Wed, 2 Sep 2026 07:50:16 +0200 Subject: [PATCH 1/2] sql_inheritance_addendum: add PK/trigger issue --- content/tutorials/sql_inheritance/index.md | 4 ++++ content/tutorials/sql_inheritance/index.qmd | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/content/tutorials/sql_inheritance/index.md b/content/tutorials/sql_inheritance/index.md index 813fd8b5d..6b3ff20f5 100644 --- a/content/tutorials/sql_inheritance/index.md +++ b/content/tutorials/sql_inheritance/index.md @@ -618,6 +618,10 @@ Even if the computational load would be equivalent in both the implementations I the use of `INHERITS` gives some extra conceptual structure to the data which has documentational value. Inheritance is not a general solution, and should be carefully considered. +A breaking limitation for some use cases, and probably the reason why the postgreSQL implementation of inheritance is not abundantly used, is that **primary keys and triggers are not inherited**. +Worse even, inherited tables can lead to primary key duplicates (more leads [on this comment](https://github.com/qgis/QGIS/issues/21962#issuecomment-495853940)). +I personally can work around that by defining new primary keys in the child tables (`activity_id` in `Activities`, and `pushup_id` in `PushUps`), and by having extra measures in place to enforce PK integrity. +Triggers simply have to be applied to all child tables individually, even if they only affect parent table fields. Keep in mind that postgreSQL inheritance is *structural* inheritance (I think of it as automatic `UNION`s which happen when I query the common fields; `NATURAL FULL JOIN`s play nicely into that). Advanced functionality is available with other `JOIN`s, Views, and `UPDATE` Rules. diff --git a/content/tutorials/sql_inheritance/index.qmd b/content/tutorials/sql_inheritance/index.qmd index b30541254..3dd5255af 100644 --- a/content/tutorials/sql_inheritance/index.qmd +++ b/content/tutorials/sql_inheritance/index.qmd @@ -615,6 +615,10 @@ the use of `INHERITS` gives some extra conceptual structure to the data which ha Inheritance is not a general solution, and should be carefully considered. +A breaking limitation for some use cases, and probably the reason why the postgreSQL implementation of inheritance is not abundantly used, is that **primary keys and triggers are not inherited**. +Worse even, inherited tables can lead to primary key duplicates (more leads [on this comment](https://github.com/qgis/QGIS/issues/21962#issuecomment-495853940)). +I personally can work around that by defining new primary keys in the child tables (`activity_id` in `Activities`, and `pushup_id` in `PushUps`), and by having extra measures in place to enforce PK integrity. +Triggers simply have to be applied to all child tables individually, even if they only affect parent table fields. Keep in mind that postgreSQL inheritance is *structural* inheritance (I think of it as automatic `UNION`s which happen when I query the common fields; `NATURAL FULL JOIN`s play nicely into that). Advanced functionality is available with other `JOIN`s, Views, and `UPDATE` Rules. From e5b6dba1ca433617eda389772916479d56552f46 Mon Sep 17 00:00:00 2001 From: Falk Mielke Date: Wed, 2 Sep 2026 07:56:50 +0200 Subject: [PATCH 2/2] sql_inheritance_addendum: link coding club --- content/tutorials/sql_inheritance/index.md | 8 ++++++++ content/tutorials/sql_inheritance/index.qmd | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/content/tutorials/sql_inheritance/index.md b/content/tutorials/sql_inheritance/index.md index 6b3ff20f5..6f2244352 100644 --- a/content/tutorials/sql_inheritance/index.md +++ b/content/tutorials/sql_inheritance/index.md @@ -36,6 +36,14 @@ However, an adequate logical representation of the data type hierarchy is both l Thus, inheritance might be an option to consider for joining TODO lists or field activities. I will herein explore the basic implementation, in practical use, and also assert which use cases this technique is good for. + +{{% callout note %}} + +If you would like to get started with SQL and R: the [INBO Coding Club session](https://coding-club.inbo.be/sessions/index.html) of August 27th, 2026 ([slides](https://coding-club.inbo.be/sessions/20260827_sql_in_r.html)) covered the topic. + +{{% /callout %}} + + # PostgreSQL installation (optional) To get our hands on the examples below, running some kind of postgreSQL server is required. diff --git a/content/tutorials/sql_inheritance/index.qmd b/content/tutorials/sql_inheritance/index.qmd index 3dd5255af..69fdad9c3 100644 --- a/content/tutorials/sql_inheritance/index.qmd +++ b/content/tutorials/sql_inheritance/index.qmd @@ -65,6 +65,15 @@ Thus, inheritance might be an option to consider for joining TODO lists or field I will herein explore the basic implementation, in practical use, and also assert which use cases this technique is good for. +```{=markdown} +{{% callout note %}} +``` +If you would like to get started with SQL and R: the [INBO Coding Club session](https://coding-club.inbo.be/sessions/index.html) of August 27th, 2026 ([slides](https://coding-club.inbo.be/sessions/20260827_sql_in_r.html)) covered the topic. + +```{=markdown} +{{% /callout %}} +``` + # PostgreSQL installation (optional) To get our hands on the examples below, running some kind of postgreSQL server is required.