« Time to Rotate the Profile Pic? | Main | Migrating to git from Subversion »



Feed You can follow this conversation by subscribing to the comment feed for this post.


The trouble with using enums is that, internally, the values are integers. That means that if you order them, they're returned in the order in which you specify them. This is great if the data you're creating should be numerically ordered, like, say, escalation statuses. But for states it makes no sense.A better choice is to create a domain. For states, it'd be something like: CREATE DOMAIN state AS TEXT CHECK ( value IN ('Alaska', 'Alabama', 'Arizona', );Then the values will be sorted exactly as you expect.But if you're dealing with various configurations for things, it might make more sense to keep such data in a separate table (but use the state names as foreign keys and save yourself some headaches!) and then put such attributes in those tables. For example, you might have a boolean column called "special" that's true for California. Then you can have a method in your State class that encapsulates the tricky bits.Hell, with this approach, you can in fact skip the lookup table, use a domain, an the map state names to their, um, states in a hash in the State class. Each state is effectively a singleton in this case, and then you can skip having that data in the database and just keep it in your module's memory.Just some suggestions.Theory

The comments to this entry are closed.