News for hackers. Stuff that matters.

jpmelos

Re:Representing Enums in PostgreSQL on Tuesday June 20, 2023 @01:48PM (#36407747)
I don't like this approach much because getting cryptic integers when you do a `SELECT` in the database is really cumbersome.
Re:Representing Enums in PostgreSQL on Tuesday June 20, 2023 @01:47PM (#36407712)
An enum stores a small reference to the enum value in the tuples, and the constraint approach stores the string itself. The constraint approach takes more space with (a) larger enum values, (b) more columns using them, and (c) more rows in the tables that use them. The difference depends on the characteristics of the database we're talking about.
Re:Representing Enums in PostgreSQL on Tuesday June 20, 2023 @01:44PM (#36407661)
> Is there a reason ALTER TYPE name ADD VALUE new_enum_value wouldn't Just Work for the first example for 99% of use cases?

I'm sorry, we don't have any examples in the article about adding values to enums, so I don't know to what you are referring here.

> Yes, that's true, but also very rare?

It is rare, indeed, but we just have a strong inclination towards having a clean schema, so we do prefer to clean up things that would otherwise be unused. But I understand that many people would prefer to leave them hanging there, even if they are not going to be used in any way.

Re:Representing Enums in PostgreSQL on Tuesday June 20, 2023 @01:40PM (#36407600)
That would be an improvement on the `CHECK` constraint approach if the same `CHECK` constraint is used in multiple columns, to DRY it up. The `DOMAIN` types offer the same commands for `CHECK` constraints, namely `NOT VALID` when updating the constraint, and `VALIDATE CONSTRAINT` to make sure it is valid after having updated it.
If understanding how Linux works interests you: http://www.linuxfromscratch.org/
Re:Ask HN: What was your greatest accomplishment in 2018? on Tuesday December 25, 2018 @10:06AM (#18757654)
This is something I really want to implement in 2019: a routine, and a general attitude, strategy, tactics and actions to "get my act together".
"Mindset: The New Psychology of Success". By Carol Dweck, PhD. This is a game-changer. It taught me what we believe is what really defines what we can or cannot do.