this post was submitted on 27 Jul 2024
844 points (97.8% liked)

Programmer Humor

19557 readers
1029 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 19 points 3 months ago (13 children)

SQL blows for hierarchical data though.

Want to fetch a page of posts AND their tags in normalized SQL? Either do a left join and repeat all the post values for every tag or do two round-trip queries and manually join them in code.

If you have the tags in a JSON blob on the post object, you just fetch and decide that.

[–] [email protected] 7 points 3 months ago (6 children)

I'm no expert in JSON, but don't you lose the ability to filter it before your application receives it all? If you had a reasonable amount of data then in SQL you can add WHERE clause and cut down what you get back so you could end up processing a lot less data than in your JSON example, even with the duplicated top table data. Plus if you're sensible you can ensure you're not bringing back more fields than you need.

[–] [email protected] 2 points 3 months ago (2 children)

In a traditional SQL database, yeah. In various document-oriented (NoSQL) databases, though, you can do that.

[–] [email protected] 5 points 3 months ago (1 children)

Modern relational databases have support for it too including indexes etc. For example postgres.

[–] [email protected] 2 points 3 months ago

Every major SQL database supports json manipulation nowadays. I know MariaDB and MySQL and SQLite at least support it natively.

load more comments (3 replies)
load more comments (9 replies)