logoalt Hacker News

What is better: a lookup table or an enum type?

20 pointsby todsacerdotiyesterday at 11:43 PM6 commentsview on HN

Comments

systemstoday at 2:17 AM

well uniformity and homoiconicity are very important in an ideal db management system (a.k.a a true rdbms) everything should be represent as a relation and use the same set of operators to be manipulated

separations of types and relations should be limited to core atomic type, string, int , date etc ... (althought date is debatable as is not usually atomic in most cases, and many dbs end up with one more date relations)

anyway, always use a table .. when its a choice

show 3 replies
CuriouslyCtoday at 2:26 AM

From a maintainability standpoint lookup tables are miles ahead, but from a DX perspective there are a few cases where enums are nice. Honestly I probably would never use enums again, I feel like it's caused pain every time I've done it.

sublineartoday at 2:08 AM

Basically ugly no matter what.

In a lot of web apps this need tends to be related to validation, so many just do these lookups and simple comparisons in their app logic and based on static values from config files long before any db query is made. Sometimes you just don't need to involve the database and the performance would be better for it anyway.