Strange Symphonies The whole is greater than the sum of its parts

1May/072

Avoid Using A Field Called ’status’

'status' sounds like a good name for a field name doesn't it? It can indicate whether your Post is draft, published or private. Or may be it can be used to indicate the current stage that your Product is in, ie: manufacturing, cleaning, testing, complete.

Surely sound's like a brilliant solution doesn't it? And it is actually!

Except for one thing.

Avoid Using a 'select' Field

Except MySQL uses the keyword 'status'. So if you wanted to do queries like so:
SELECT status FROM users

you would need to enclose the 'status' field in back ticks, like so:
SELECT `status` FROM users

Now that isn't cool at all, because using find method with conditions can be highly irritating, and doesn't look clean at all.
Post.find :all, :conditions => ["`status` = ? OR `status`", 'published', 'private']

So if you actually do decide to use a field called 'status' and enclose it within back ticks, then you'll run into another problem. Database independence.

SQLite does not support back ticks. So if you like to develop and test on SQLite initially, and similarly since your application has been comfortable with SQLite, you decide to also use it production. But what happens when SQLite can't scale anymore? Well you've got to move elsewhere. Unh unh right?

Note: I am inexperienced with PostgreSQL, so maybe others can update me on this.

Alternatives

Other alternative I have been using is to call the field 'stage' or 'state'. There are probably tons of other possibilities out there, but do avoid using a field called 'status'.

Any suggestions for other possible alternatives to use?

Related posts

Tags

    No tags for this post.
Comments (2) Trackbacks (0)
  1. What version of mySQL uses ’status’ as a keyword? According to the list of reserved words at , ’status’ isn’t listed. I’ve also used ’status’ as a field name in other applications on mySQL without issue.. Curious as to which version of mySQL has a conflict with this word.

  2. looks like the blog software didn’t like my url, here it is again:

    http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html


Leave a comment


No trackbacks yet.