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 !

4

u/Dokiace Sep 24 '20

is this JSONB storage a new thing implemented in postgres?

14

u/mobydikc Sep 24 '20

version 9.4 I think.

6

u/Dokiace Sep 24 '20

So it's been out for a while huh, how come I never heard of this, so you can just INSERT <JSON> into TABLE and it will handle that?

17

u/booboorocks998 Sep 24 '20

They get inserted like strings. But the column type has a bunch of special features, like you can query into the json for your select or check a value in the where.

https://www.postgresqltutorial.com/postgresql-json/

2

u/Dokiace Sep 24 '20

is this not implemented widely in the industry? I dont have that much professional experience but I haven't seen this one implemented anywhere in the production

10

u/booboorocks998 Sep 24 '20

Not likely if your database has been around for more than a couple years.

Even Microsoft SQL Server supports json columns now though, so it's sort of picking up.

When you use that type, you trade off most of the benefits of relational data. So it is only really great for some use cases. But for those use cases, it is awesome!

It's also a nice way to just store blobs of data in a database rather than a file system or cloud storage. You don't lose out on the relational features since you wouldn't have them with the alternatives anyways.

4

u/utdconsq Sep 24 '20

I used it for quite a few years there. Super, super useful. Happy to go there again but where I'm at now were stuck with mongo. Horrid system by comparison.

8

u/DrunkensteinsMonster Sep 24 '20

JSONB is a column type. Possible use case: you have an object that has another object as a property. Instead of creating a new table and having a foreign key, just serialize the property and store it in a JSONB column

2

u/Dokiace Sep 24 '20

So just like in mongo when you're inserting a new object into an existing object? that's neat

4

u/[deleted] Sep 24 '20

But it's not mongo, so it won't eat your data :P

1

u/LordSeptum Oct 03 '20

It's been around for 8 or so years. Indexable keys and values, input json, outputs json. Pretty straightforward. I prefer jsonb over json

Documentation:

https://www.postgresql.org/docs/13/datatype-json.html

-13

u/blackAngel88 Sep 24 '20

What do you mean with JSONB indexing? Sure you can create index on jsonb_column->someField, but I don't think Postgres automatically indexes the json like you would expect from MongoDB on the documents..?

Postgres is awesome and the JSONB can be very useful. But it's not a 100% substitute for anything MongoDB.

6

u/mateoestoybien Sep 24 '20

You can create a GIN index on jsonb that indexes a variety of different operators. It's not perfect, but it's more than the functional index you put above. End of the day, postgres does not store statistics about sub documents in json, so you'll never get amazing performance when filtering using jsonb; it's best to use it to store data that is just along for the ride.

4

u/[deleted] Sep 24 '20

MongoDB webscales?

2

u/FREEZX Sep 24 '20

Never said it's a substitute, but it's a damn sweet middle ground, considering that most times you know what you want to index, even in JSON.