I often need to update a table using values from a different table and most of the time the quickest and also dirtiest solution is simply to do a subquery. A better and cleaner solution is to use the UPDATE .. SET .. FROM:
Let’s describe our case with an example:
I have a table
journey_pattern in which I need to update the name based on the name of its line. I can find the line by joining 2 other tables:
Using a subquery I can simply do:
But what if
lines.name is empty or null ? I need to check that case using a
CASE .. THEN .. ELSE .. END. The inline subquery will end up being quite difficult to read. …
It’s a common task in my current position to download and restore client schema on my local postgres to debug it. So I decided to build a small CLI tool to help me.
Fully inspired (to not say copy/pasted) from this post by Lukas White
and James Hibbard:
pg-schema-restorer in my terminal and the following appears:
The tool look for the
.backup files in my folders and subfolders of
~/Downloads and ask me to select one.
Once chosen it asks me the name of the schema (try to deduce it from the…
So you just finished your super webapp/api and it’s already going live. I’ll show you a simple way to add a basic monitoring on your server without adding a new dedicated app to do the task, using only your CI/CD
Say you want to check if your app responds with an HTTP 200. The following command will exit with error if so:
curl — silent — show-error — fail https://my-webapp.fr/
If you want to verify that a specific endpoint respond with a json object containing a predefined number of elements. We’re using jq:
#/bin/shnbElements=$(curl https://my-webapp.fr/api/endpoint | jq length)
if [ $nbElements -eq 2 ]; then
echo "No errors, the list of nbElements is 2 as expected"
echo "Oops, something went wrong, nbElements should have 2 elements and only $nbElements were received..." …