22 Followers
·
Follow

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:

Image for post
Image for post
PostgreSQL logo

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: routes and lines.

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:
Build a JavaScript Command Line Interface (CLI) with Node.js

How it works

I type pg-schema-restorer in my terminal and the following appears:

Image for post
Image for post

The tool look for the .backup files in my folders and subfolders of~/Documents and ~/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)
echo $nbElements
if [ $nbElements -eq 2 ]; then
echo "No errors, the list of nbElements is 2 as expected"
exit 0;
else
echo "Oops, something went wrong, nbElements should have 2 elements and only $nbElements were received..." …

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store