r/programming • • Sep 24 '20

PostgreSQL 13 Released!

https://www.postgresql.org/about/news/2077/
1.3k Upvotes

236 comments sorted by

View all comments

60

u/tomma5o Sep 24 '20 edited Sep 24 '20

Sorry FE dev here, why you guys prefer postgreSQL over mySQL?

103

u/FREEZX Sep 24 '20

I prefer Postgres for it's JSONB storage and indexing, basically allowing it to take any JSON data as a field and quickly look things up. I see it as having benefits of NoSQL databases while keeping it relational.

36

u/ItalyPaleAle Sep 24 '20

JSON support is a killer feature for me too. MySQL did add JSON support in a recent-ish version, but last I checked it wasn’t as complete as Postgres’

Another great feature is PostGIS, for spatial data (think maps and stuff that goes on a map). It also has great performance and scales well.

6

u/yesman_85 Sep 24 '20

This is one of the game changers for us too, putting indexes on a JSONB column is very useful.

10

u/tomma5o Sep 24 '20

Thank you this is very helpful response !

→ More replies (15)

62

u/jailbreak Sep 24 '20

The company behind MySQL was bought by Oracle, a company that has a reputation for being ruthlessly profit-driven (one joke goes that it stands for One Rich Asshole Called Larry Ellison - the founder), who killed off a previous acquisition of theirs, Sun Microsystems, makers of Java (see also this great rant) and Oracle's primary product is a competing SQL database. As a consequence MySQL has been languishing, coasting along on its existing popularity (it was very widely used a decade or two ago due to being part of the LAMP stack that powered most PHP-web-apps back then) but the open source community has become skeptical of it due to its new owner. A community fork of MySQL exists, MariaDB, but it seems the OS community has mostly rallied around PostgreSQL as the de-facto replacement for MySQL. At the same time, postgres is being very actively developed, and produces stable and fast releases while adding great new features. This means they've long since caught up with MySQL feature-wise (IIRC there used to be some advantages to MySQL when it came to performing schema changes without locking the DB, but they've long since remedied that) and as far as I can tell even overtaken MySQL on most parameters, e.g. with their JSON store, that allows you to use it as a schemaless key-value store if you get that NoSQL itch. So anyways, today for new projects, there's basically no reason to choose MySQL over postgres, you get great performance, lots of features, and don't need to concern yourself with somehow ending up under Oracle's thumb.

14

u/rainman_104 Sep 24 '20

I'd even argue that MySQL really became popular because of LAMP and that MyISAM tables had zero locking issues that transnational RDBMS had, and at the time it was a lot easier to get started with MySQL than Postgres. Postgres was much more feature rich compared to MySQL 4.0.

I'm actually honestly surprised Firebird SQL didn't get any of the momentum after the Oracle acquisition of Sun.

182

u/mobydikc Sep 24 '20 edited Sep 24 '20

SQL is just a language. Structured Query Language or something like that.

PostgreSQ, MySQL, MIcrosoft SQL Server, Oracle, are just some of the products that use SQL.

Postgres is free, open source, reliable, fast, and powerful.

edit the comment I replied to originally said "normal SQL" instead of "mySQL"

53

u/[deleted] Sep 24 '20

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.

30

u/[deleted] Sep 24 '20

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.

23

u/sveri Sep 24 '20

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.

→ More replies (16)

23

u/watsreddit Sep 24 '20

Unfortunately, they are not equivalent beyond the most basic of uses. MySQL lacks in many of the more advanced features compared to Postgresql and SS. Postgresql handles concurrency in particular much better than MySQL. MySQL also cannot index JSON columns, which is a pretty significant performance problem.

20

u/mobydikc Sep 24 '20

Like I said, Postgres (IMO) is faster, more powerful, and more reliable than MySQL.

The OP editted their comment to say "mySQL" whereas before it said "normal SQL".

64

u/tomma5o Sep 24 '20

Ok thanks for the non toxic response ❤️

→ More replies (1)
→ More replies (1)

16

u/QuotheFan Sep 24 '20

I recently switched from mySQL to postgres.

Postgres allows you to create schemas within databases, which allows you to organize database beautifully. Secondly, postgres supports UTF-8 out of the box, mysql's support for UTF-8 is umm, weird. Overall, I didn't expect to be able to notice the difference b/w postgres and mysql at the level I am working but I did.

(I am not very experienced with web-dev, so take my opinion with a pinch of salt)

→ More replies (2)

15

u/baryluk Sep 24 '20 edited Sep 24 '20

PostgreSQl is know for ita reliability and stability. I lost some databases in mysql installs. Never again.

PoatgreSQL is in general more advanced and customisable. There are various extensions you can write to add new types, indexes, aggregates, helpers, etc. You can do advanced partitioning natively, more advanced indexes, perform very complex analytics queries more performant, while the database is still working with other clients. Use more advanced authentication methods. Trigger , scripting and stored procedures are more advanced. Error handling in data and queries is handled more reliably. Mysql will sometime accept nonsense , conver to something and loss user data without notifying you. Granted it is documented for mysql, but still a shitty design. A lot of these features were available in PoatgreSQL years or decades ago, and mysql is catching up a bit. Making reliable database backups is somehow easier with PostgreSQL. And probably many more, like advanced aggregates, parallel queries, etc. Better and more advanced transaction control support. Historically PostgreSQL provided more advanced and flexible replication support. Also historically mysql was not ACID, making it almost useless for serious database work.

Mysql is popular because it is easier to setup initially, and was super easy to use from php, which lead to its popularity. Also myths of PostgreSQL being slow. In my expirience under real complex conditions, properly configured and used, with comparable functionality, PostgreSQL is faster. But that depends on application and requirements.

14

u/poloppoyop Sep 24 '20

Until recently, MySQL did not have good support for window functions, CTE or json fields.

And usually the Postgres team has a philosophy of releasing features when they have a good working solution. Not "as fast as possible and we'll see how to handle the corner cases later on".

27

u/[deleted] Sep 24 '20

What is normal SQL?

→ More replies (4)

37

u/Chousuke Sep 24 '20

MySQL has a history of not really caring about data integrity; for me, that alone is a sufficient reason to avoid it. After all, why would I use a database that does a bad job at its primary purpose?

It's not quite as bad nowadays as it used to be, but the valid reasons to choose MySQL over PostgreSQL have also diminished.

24

u/o11c Sep 24 '20

Sanity and standards-compliance.

MySQL is a literal joke.

12

u/DeliciousIncident Sep 24 '20

It's not owned by Oracle, so that's a giant plus already.

21

u/G_Morgan Sep 24 '20

MySQL used to eat data in the past so a lot of people dumped it around that time.

→ More replies (11)

14

u/nightshade000 Sep 24 '20

To add to others response, there are many non technical and/or political reasons as well. For example, MySQL is owned by Oracle, and though it's 'free' there are many people who avoid anything Oracle like the plague. Another might be that the postgres implementation of sql is relatively close to the sybase and ms sql implementation and is an easier transition into a free yet still competent rdbms for people coming from those other products.

6

u/[deleted] Sep 24 '20

I suppose that nobody sane still uses mysql and that when mentioned we are all talking about mariadb...

→ More replies (46)