In the previous post I demonstrated how small typos in SQL become large logical errors, and how a “proper” type system could help in preventing these. This time I explore how PostgreSQL’s enum data type can be leveraged to gain some data safety and prevent logical errors.
In PostgreSQL the enum data type offers some type safety, for example:
CREATE TYPE d1 AS ENUM ('1', '2', '3'); CREATE TYPE d2 AS ENUM ('1', '2', '3');
Enumerated values are labels, hence the quotation marks. Continue reading “Types and Typos in SQL ”