1 hour ago · Tech · hide · 0 comments

PostgreSQL databases support having enumerated type (enum) columns so that the column only accepts one of a predefined set of values. I’ve worked with ORMs like Active Record from Ruby on Rails. Using Active Record, I could work with database columns that only allowed a certain set of values. I always thought that was only possible due to the ORM layer abstracting away these things, but that’s not the case. Enums can be enforced at the database level (at least with PostgreSQL). I’ll demonstrate on a PostgreSQL container with a simple table. I’ll be using Podman. You can also use Docker to follow along, just replace podman with docker in the commands. Make sure Podman/Docker is running, then run the following to get a running PostgreSQL container locally: podman run -d --name enum-demo -e POSTGRES_PASSWORD=postgres docker.io/library/postgres:18Then exec into the running container: $ podman exec -it enum-demo psql -U postgres psql (18.6 (Debian 18.6-1.pgdg13+2)) Type "help" for help.…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.