I still remember when I heard PostgreSQL for the first time. It was around 2001, when my former room mate mentioned that he was a maintainer for PostgreSQL on Debian. At that time, I was still studying electrical engineering, so database systems were no concern to me. But I knew something was there and even used PostgreSQL for some projects, professional and private. Today I held a presentation for my fellow developers at wer denkt was, comparing PostgreSQL with MySQL.
Over the last years, both systems have added lots of functionality and became much closer with respect to features. The Dumper Blog did a comparison of MySQL 8 and PostgreSQL 10 in 2018. While MySQL added common table expressions and window functions and improved JSON support and geospatial features, PostgreSQL introduced logical replication, semi-synchronous replication and declarative partitioning.
In this blog, I will highlight the remaining differences between the two most widely used open-source SQL implementations.
One thing only PostgreSQL can do is table inheritance, like in object-oriented programming languages.
A view in SQL is a saved query which can be used like a table.
Full outer joins
A full outer join can also be useful for some special kind of queries. MySQL does not support this, while PostgreSQL does.
One major difference is the naming of data types. To convert safely, refer to MySQL to PostgreSQL Types Mapping. This is a major obstacle when porting SQL scripts, better use a tool like pgloader which has built-in conversion logic for a variety of input formats.
This is a crucial functionality for the AppJobber application, which allows people to see all available micro jobs in their selected map range. So this runs down to selecting entries from a large table within a bounding box. While MySQL has built-in support for geospatial data types, PostgreSQL uses the PostGIS extension. The Boston Geographic Information Systems did a detailed comparison of geospatial features between MS SQL Server, MySQL and PostgreSQL/PostGIS, which seems a bit outdated.
So I was running a sample bounding-box query on all available jobs, using a bounding box around Darmstadt. It took MySQL roughly a second to complete the query, PostgreSQL did it in less then 400 ms. However, the two queries were a bit different, as MySQL had location data readily stored as blob and PostgreSQL used a converted geometric point type.
There is ample discussion about performance, most favoring MySQL for read-heavy loads and PostgreSQL for read/write-heavy applications. So this depends very much on the application in question.
After all, I hoped to show that PostgreSQL is a viable alternative to MySQL with more advanced features.