Reputation: 1507
My application is processing user requests. Each request has the following statuses: "some parts of request received from user", "all parts received", "started processing", "result is ready", "result is sent to user". I want to store request status in a database as a single column. Right now I have two ideas how to implement it:
Use a string column. Each request status is stored as text. For instance, a request which was sent to the user, will have a status value of "sent".
Use an integer column. Each request status is stored as int. For instance, "some parts of request received from user" = 1, "all parts received" = 2, "started processing" = 3, "result is ready" = 4, "result is sent to user" = 5.
I see there is no point in using more than one byte when one byte is enough. I even agree to write converting code (text status -> integer status and vice versa). But what should I do with sudden intermediate statuses? Is there a different approach?
Upvotes: 1
Views: 1870
Reputation: 12883
Storing the data as an integer does not have to hide your information, you can create a lookup table that relates the integer constants to their textual values, and then join them if you want to look at a textual representation of the data.
On the other hand, unless you plan on storing many millions of rows, or have to process many thousands of transactions per second, the extra few bytes in your state table will probably not make that much of a difference.
I'm not sure what you mean by the latter part of your question when you say, "sudden intermediate statuses." Are you worried about having to add more states later, or are you talking about modeling transitions from one state to the next as states in your finite state machine?
Upvotes: 1