PostgreSQL Foreign Keys
If you're going to have two tables reference each other, use foreign keys where possible. It forces useful constraints to make sure delete and update behaviors are intentional and it makes the queries faster.
All of my published content
If you're going to have two tables reference each other, use foreign keys where possible. It forces useful constraints to make sure delete and update behaviors are intentional and it makes the queries faster.
How to create a many-to-many relationship in PostgreSQL. This is a continuation of the notes on Foreign Keys.
A simple diagram covering the basics of SQL joins.
A guide to connecting to a PostgreSQL database using the pg package in Node.js, explaining the differences between a client and a pool of clients. Also emphasizes the importance of parameterizing queries and sanitizing user inputs to prevent SQL injection attacks.
A brief overview of common SQL commands used for interaction with PostgreSQL. It explains how to insert single and multiple records, perform upsert operations, update and delete records, and select specific columns.
PostgreSQL provides a large number of functions and operators for the built-in data types. Here I briefly go over LIKE and ILIKE, two symbols used for character matching, and the CONCAT function. These all allow for basic fuzzy searching of your data.
Here is a quick guide on how to run PostgreSQL in Docker. It further explains how to create a database, tables, and records, as well as how to drop and alter tables. It also provides examples of psql commands and explains how to use them.