Note that yes, they all use "SQL", but that most non-trivial SQL you write will probably not be easily ported from one to the other. Because often you'll use server-specific functionality or syntax.
I don't agree with this statement. There may be small syntactical differences with window or aggregation functions, engine hints, and similar, but for simply writing queries, the overwhelming majority will be ANSI SQL or will have trivial differences that can be addressed with find-and-replace.
The real differences start when you get into stored procedures/temp tables/loops, and database administration tasks, including indexing.
I find the differences are highly overstated in general.
Sorry, but this is not true. For our current product we have to support 5 different databases and the differences already start with creation of tables, indexes and unique columns.
Also the column types and their handing are different. Let alone stuff like JSON support.
That said, I still prefer using jdbc and writing plain SQL over having to use some mapper.
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!
I find things like date manipulation functions & syntax to vary widely across each system as well. This in my opinion is a pretty simple and commonly used operation which is hard to work around
Why is there always someone that has to come in and be like “ACTUALLY...” while missing the point. He covered your argument by saying “non-trivial sql”. That’s the point. If it’s trivial it likely can be easily ported. Non-trivial sql would be stored procedures, ctes, functions, nested sub queries with grouping and joins, etc.
You’re just saying what he already said using specific examples.
Yes, I didn't mention that, thought it was obvious. Again, a very simple change.
I have 10 years using T-SQL and I have never seen a TOP PERCENT in the wild.
My point was never that no changes are needed, but the changes are trivial in nature. The magnitude of these changes pale in comparison to those required for DBA-related tasks.
Not really for pivot, unpivot, outer apply, cross apply, any stored procedure or function using if statements (not trivial enough to search and replace), table valued functions that take custom types as inputs, convert vs cast, and the list goes on. And these are all pretty basic things all database can do.
Yes it can be done as the comment you replied to stated, but no it is not as trivial as you make it out to be.
I once had to migrate from a MySQL to postgres database. Took months. Aggregations were terrible, but the worst was the nightmare of how MySQL doesn't believe that data types should make sense.
So while your queries will work between the two, the data returned by one will be horrifically mangled.
60
u/tomma5o Sep 24 '20 edited Sep 24 '20
Sorry FE dev here, why you guys prefer postgreSQL over mySQL?