Hacker News new | ask | show | jobs
by mbrubeck 5063 days ago
I think tdavis is referring to this example from maciej's post, where inserting 'y' into a tinyint field silently converts it to 0 instead of throwing an error:

     mysql> create table demo(int tinyint(1), bin binary(1));
     mysql> insert into demo(int, bin) values ('y', 'y');
     mysql> select * from demo;

     +------+------+
     | int  | bin  | 
     +------+------+
     |    0 | y    |
     +------+------+
1 comments

It's not silent:

    mysql> insert into demo values ('y', 'y');
    Query OK, 1 row affected, 1 warning (0.01 sec)

    mysql> show warnings;
    +---------+------+------------------------------------------------------+
    | Level   | Code | Message                                              |
    +---------+------+------------------------------------------------------+
    | Warning | 1366 | Incorrect integer value: 'y' for column 'n' at row 1 |
    +---------+------+------------------------------------------------------+
If you want this type of warning to be treated as an error then adjust the setting:

    mysql> SET sql_mode = 'TRADITIONAL';
    mysql> insert into demo values ('y', 'y');
    ERROR 1366 (HY000): Incorrect integer value: 'y' for column 'n' at row 1
Which brings us right back to what tdavis said in the first place: "As much as anything else, this is another great example of MySQL letting you shoot yourself in the face by default."
You are aware that this whole thing is theoretical since he set the field to bin (i.e. binary)? No database at all would have prevented this.

MySQL chose to coerce fields to fit the type. You don't like that choice, but other people find it useful. And MySQL gives you a choice to change it if you wish.

Judging by how popular and successful they are I think those chose correctly.

This article is a success story for MySQL because maciej is using MySQL.

This article is a failure story for maciej. MySQL may have chosen correctly for its own popularity (although that's debatable; this choice might not be a success factor) but it did not choose correctly for the success of its users, with this article being a clear example.

It's not theoretical. MySQL by default allowed type coercion out-of-box that is nonsensical. Sure, type coercion can be nice, but I'd prefer none over if it not failing and coercing bin('y') to 0.

Attributing their success to their choice of DB is insulting at best.

MySQL chose correctly, not maciej.

The coercing bin('y') to 0 makes no sense though - I agree with you there.

Those two statements conflict with each other and I don't see how you reconcile those without placing blame on MySQL.
MySQL's warnings are silent, in the sense that the web application will never act on them. Guessing instead of failing early is a poor choice for a relational database, and is only explained by MySQL favouring ease of use and porting over data integrity.