sql_inheritance: Tutorial about using postgreSQL Inheritance#371
sql_inheritance: Tutorial about using postgreSQL Inheritance#371falkmielke wants to merge 4 commits intomasterfrom
Conversation
ElsLommelen
left a comment
There was a problem hiding this comment.
Interesting, and nicely written! I just added some minor suggestions, I hope they are useful (otherwise feel free to ignore them).
(I'll let you have a look first and I'll approve when you are finished, as I recently encountered some situations where the approval had to be done again after new commits were added.)
|
|
||
| However, installing a local postgreSQL server is not all too complicated, so I took the occasion to list the simple steps. | ||
| These will work on an arbitrary linux system (e.g. in a [container](https://tutorials.inbo.be/tags/containers/)), with minor variance. | ||
| Installation on Windows can be [achieved via an installer](https://www.postgresql.org/download/windows/) and documented elsewhere. |
There was a problem hiding this comment.
| Installation on Windows can be [achieved via an installer](https://www.postgresql.org/download/windows/) and documented elsewhere. | |
| Installation on Windows can be [achieved via an installer](https://www.postgresql.org/download/windows/) as documented elsewhere. |
Or: and is documented elsewhere
| These will work on an arbitrary linux system (e.g. in a [container](https://tutorials.inbo.be/tags/containers/)), with minor variance. | ||
| Installation on Windows can be [achieved via an installer](https://www.postgresql.org/download/windows/) and documented elsewhere. | ||
|
|
||
| First off, install the right `postgresql` package for your operating system; usually it is called `postgresql`. |
There was a problem hiding this comment.
Is this also needed for Windows OS, or does the above installer do the whole installation including the right package?
| ) INHERITS (Activities); | ||
| ``` | ||
|
|
||
| Here are two changes from above: the identifier column may be omitted (it is inherited), and inheritance is established by the keyword `INHERITS (parenttable)`. |
There was a problem hiding this comment.
What about unique primary keys for these inherited tables? Do they need an extra PK, or is it enough to inherit the PK from table Activities? You may want to add the PK in the earlier example to demonstrate this more clearly.
| -- this stdouts "UPDATE 0", but did actually work: | ||
|
|
||
| SELECT * FROM AllActivities; | ||
| ``` |
There was a problem hiding this comment.
Why is the output missing here?
| LINE 2: SET duration_s = 16 | ||
| ^ | ||
|
|
||
| This might be intentional, if your front-end is specific for each activity type. |
There was a problem hiding this comment.
It could be useful to mention how these tables could be updated in an easy way: the below part is titled advanced and it may discourage readers that are less familiar with databases but want to incorporate the inheritance for a better database structure. While it might not be needed to demonstrate this all in code, you may want to mention in one sentense that this update could be performed in table PushUps (if true)?
Description
I was evaluating whether to overhaul part of our main database by using inheritance.
This required some sandbox data to test specific cases.
I figured it might be useful to immediately write up a tutorial notebook.
I doubt that many people at INBO will have immediate use for it; however, I did not find many other practical tutorials which explore the details and implications for our specific use case.
Task list
tutorials/content/index.md. In case of an Rmarkdown tutorial I have knitted myindex.Rmdtoindex.md(both files are pushed to the repo).yamlheader:authorsyaml tag, using[MY_AUTHOR_ID]. An author information file exists in<tutorials>/data/authors/<author>.toml.categoriesto the YAML header and my category tags are from the list of categories.tags(i.e. keywords) in the YAML header to improve the visibility of the new tutorial (see the tags listed in the tutorials website side bar).dateis in formatYYYY-MM-DDand adjusted.Previewing the pull request
Thanks to GitHub Actions, an artifact (=zip file) of the rendered website is automatically created for each pull request.
This provides a way to preview how these updates will look on the website, useful to contributors and reviewers.
Instructions to preview the updated website
Downloads/tutorials_preview.httpsites on your local machine. One such option is theservrpackage in R:& '\C:\Program Files\R\R-4.4.2\bin\Rscript.exe' -e "servr::httd('./tutorials_preview')" -p8887(make sure to adjust the path to yourRscript.exe; on Linux, simply useRscript -e [...]).Note: for step 3, you can use any other simple HTTP server to serve the current directory, e.g. Python
http.server:python -m http.server 8887 --bind localhost --directory path/to/tutorials_previewAlternative: Locally Building the Site
Alternatively, you can build the entire site locally (see the README for instructions); the Hugo preview server will update changes on the fly.
This requires Hugo to be installed on your computer.