Within the context of simple queries that's broadly true, but when people worry about portability, they're not usually worried about simple queries.
In the space of queries, there are some important features that may be missing in one implementation or another, or that may have implementation differences. My favorite part of T-SQL was the WITH common_table_expression syntax. Transactions are hugely important in safety-oriented application architecture, and it seems like every engine has its own notion of how they should work.
And queries are only half of what needs to get ported. Incompatibilities are even more common in schema declaration. MySQL datetimes aren't timezone aware. PostgreSQL can supposedly be made to support case-insensitive collations, by hacking the underlying OS!
I'm never going to forgive MySQL, even if they fix this: I spent two years on a MySQL backed application, fixing problems throughout the stack including the DB schema. It was two years before I realized that none of the foreign keys I'd written were actually enforced by the DB. Apparently MySQL reads inline foreign key declarations as "valid standard SQL", but silently ignores them.
Sure. Part of what's so egregious is that it's not documented better, although it would be a pretty baffling and bad design even if it were well documented.
Here's the documentation page for table declarations. Right at the top is the syntax description like you'd expect. If you follow the definitions create_definition -> column_definition -> reference_definition, you'll see that you can declare a foreign key in MySQL the same way you're probably accustomed to from other languages:
CREATE TABLE table_x
y_values INT REFERENCES table_y (y_values);
And if you run that, the engine will say "OK, that worked and your table exists. But there won't actually be a foreign key!.
If you read almost half way down that page, there's a blue "Important" box, the last paragraph of which mentions that "MySQL parses but ignores inline REFERENCES specifications". It's also mentioned on this other errata page. But if you didn't already know there was a problem, you'd never find these warnings.
Ooh okay, what I understood from your previous comment was that it ignored foreign keys when declared in the CREATE TABLE statement in general, not just when you put REFERENCES table (x) on the column. Thanks for clarifying that!
18
u/ShapeOfMatter Sep 24 '20
Within the context of simple queries that's broadly true, but when people worry about portability, they're not usually worried about simple queries.
In the space of queries, there are some important features that may be missing in one implementation or another, or that may have implementation differences. My favorite part of T-SQL was the
WITH common_table_expressionsyntax. Transactions are hugely important in safety-oriented application architecture, and it seems like every engine has its own notion of how they should work.And queries are only half of what needs to get ported. Incompatibilities are even more common in schema declaration. MySQL datetimes aren't timezone aware. PostgreSQL can supposedly be made to support case-insensitive collations, by hacking the underlying OS!
I'm never going to forgive MySQL, even if they fix this:
I spent two years on a MySQL backed application, fixing problems throughout the stack including the DB schema. It was two years before I realized that none of the foreign keys I'd written were actually enforced by the DB. Apparently MySQL reads inline foreign key declarations as "valid standard SQL", but silently ignores them.