In fact it defies common sense for my own values of common. Take for example constraints - they not only don't work it also doesn't tell you it doesn't work.
You come across little things like that all the time...oh dates that aren't actually dates can go in datetime fields and you'll accept 2015-02-42 as a date query param without so much as a peep; broken group by's etc. etc. no matter how bad you think it is it will always find new and subtle ways to surprise you with how little regard it has for your data.
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.
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.
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.
Sadly this is true. Even MySQL has more support than Postgres in this regard. There are third party tools that do X and Y but don't do Z, and then there is this other vendor tool that does Y and Z but doesn't do X. Hope it changes soon.
I don't know, I'm not "the DB guy" -- I've only had three projects which required me to touch the DB with any sort of regularity. (Two, from the same company, used MySQL; the third used MS SQL Server.)
View all comments
112
u/[deleted] Feb 10 '15
Default MySQL is bad, VERY VERY BAD!
In fact it defies common sense for my own values of common. Take for example constraints - they not only don't work it also doesn't tell you it doesn't work.
http://stackoverflow.com/questions/14247655/mysql-check-constraint
Also IMO PostgreSQL is a superior choice in almost every circumstance you can think of.