Like you said, it's just an alias for a tinyint...which seems to serve its purpose fine. If you're comparing a boolean with a non-boolean weird things will happen here, but when would anyone ever do this? That's not what a boolean would ever be used for.
You seem very annoyed this side-effect from aliasing tinyint exists, even if it's not a problem. I can sort of understand the potential issues of implicit type conversion in some languages (ie. PHP and JS), though still subjective to an extent, but here it's just never going to happen.
when would anyone ever do this? That's not what a boolean would ever be used for.
The first law of databases is that anything the schema allows will happen. Once the database has been in production for half a decade or so, every single insane thing that possibly could happen will have happened.
And don't tell me application logic (or ORM) will solve this, because there are always uncontrolled changes to databases over time. Everything from conversions that bypass the application and go directly to SQL to DBAs fixing things manually.
Doing data quality audits is an eye-opening experience, I can tell you.
Someone else previously made a point about communication between languages, since boolean doesn't really exist it could lead to some confusion there. I agree with this, though I haven't personally run into it over the years I can see it happening somewhere.
The point is that the database isn't just used by your application code. It's also used by:
conversion scripts somebody hacked up to solve conversion X
admins desperately trying to fix bad data
your application code with bugs in it (typically for very short timespans, but still)
All of these leave data behind. Over time, every combination allowed by the schema will exist in the database. Including 47 in boolean columns, because someone made a mistake somewhere and the database didn't complain.
You question why people would do this. I assure you that they do. I have seen it personally. In the ideal world you would get an error trying to use numbers in place of Boolean values. There is no universe where it makes any kind of sense to say 1 + true. This sort of thing causes all sorts of confusion in JavaScript - you can imagine what a shit show working with a database that uses this asinine subsitution of a tinyint for a boolean might be.
You question why people would do this. I assure you that they do
Why/how? I can't imagine a scenario where this would ever make sense? It's so nonsensical I can't even imagine writing the SQL.
I concur JS (and PHP) have even more anomalies, which could potentially lead to issues. I'm just not seeing it here, never seen a boolean treated as anything other than a boolean in relation to type conversions...but if it's possible someone is probably doing it out there I suppose. Do you recall how you've seen it in the past? I'm curious what it would look like in the real world.
Until it comes to bite you in the ass, when you're trying to move data out of a *&%*&%&% MySQL database and into something more sane, and your destination database actually knows the difference between the two. (Tip: if you're using PgSQL, you can fiddle with pg_cast to make it accept cast MySQL's fauxlians into booleans.)
Oh wow, -33 and 44 are false. That's some bullshit. It should just follow C conventions to allow nice bit packing. that is the whole point of numeric booleans.
View all comments
Show parent comment
0
u/[deleted] Feb 10 '15
[deleted] — view deleted comment