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:

you would need to enclose the ‘status‘ field in back ticks, like so:

Now that isn’t cool at all, because using find method with conditions can be highly irritating, and doesn’t look clean at all.

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?

This entry was posted in ActiveRecord, Databases. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

2 Comments

  1. Adam Cohen
    Posted 2 November, 2007 at 12:25 pm | Permalink

    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. Adam Cohen
    Posted 2 November, 2007 at 12:27 pm | Permalink

    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

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*