this post was submitted on 26 Oct 2023
285 points (96.4% liked)

SQL - any and all

302 readers
1 users here now

For discussion about SQL and databases. All versions welcome.

founded 1 year ago
MODERATORS
285
submitted 8 months ago* (last edited 8 months ago) by DeadNinja to c/sql
 

Jesus died at 33, so that can't get returned in the query response lol

top 50 comments
sorted by: hot top controversial new old
[–] [email protected] 61 points 8 months ago (3 children)

SELECT user FROM db WHERE age BETWEEN 25 AND 35;

Fuck your mongo

[–] [email protected] 22 points 8 months ago

Mongo only pawn in scheme of life.

[–] [email protected] 6 points 8 months ago* (last edited 8 months ago) (1 children)

We just got a ticket in, our users need several new fields in the user table

Relational virgin:

NNNNNOOOOOO I'll need this sprint to modify the user table and write the etl script

NoSQL Chad:

private String newField1;

private boolean newField2;

private Object newField3;

//And now, I close the ticket and go get lunch beers.

[–] [email protected] 1 points 8 months ago* (last edited 8 months ago)

You do know that a large majority of SQL flavours support JSON columns?

[–] bus_factor 45 points 8 months ago (2 children)

All this talk about query format and no one discussing the dogshit database design requiring the record to be updated whenever the user has a birthday? Store the day of birth and do the math at query time at least!

[–] [email protected] 7 points 8 months ago

Does mongodb have virtual columns?

[–] asterfield 29 points 8 months ago

I’m no mongo fan, but this is ragebait.

You can write it like this, but you can also write {age: {$gte: 25, $lt: 30}}

If you’re going to dunk on mongo, let’s talk about how db.collection.update() replaces the whole record by default instead of updating keys

[–] ericbomb 17 points 8 months ago (1 children)

Thanks for letting me know that if I'm ever asked if I'm willing to learn mongo the answer is no.

[–] Theharpyeagle 14 points 8 months ago* (last edited 8 months ago)

I do believe Mongo has some valid niche use cases, but far, far too many people think it's just a no-worries way to dump objects into a database without having to deal with all that fussy schema stuff. They only realize their mistake when it comes time to actually use that data as anything other than a huge, unmanageable blob of nested fields.

Granted, Mongo's marketing kind of encourages this.

[–] muel 10 points 8 months ago (4 children)

Slightly off-topic: I get so confused with age conventions. I’m self-taught and do some ad-hoc work for the organization I work for (where no one else has any interest).

To get users between 25 and 30, wouldn’t you want strictly less than 30? And greater than or equal to 25? Or for age is it inclusive?

[–] Whelks_chance 16 points 8 months ago (1 children)

Realistically you wouldn't store age, you'd store birthdate or possibly a datetime value, and calculate it from there

[–] hansl 6 points 8 months ago

First Normal Form users unite!

By the by, as someone who have used both NoSQL and SQL extensively (once in the same project), the trick of NoSQL is that you shouldn’t use FNF and compute that at write time. The idea is that it’s faster to MapReduce pre calculated values since that’s the operation you want to optimize in a NoSQL world. A lot of people get that wrong and just replace MySQL with Mongo without rethinking usage and schemas.

But even in a NoSQL context I’d rather use a Postgres jsonb column over MongoDB.

[–] [email protected] 5 points 8 months ago

This is a question for story refinement.

[–] V0lD 5 points 8 months ago* (last edited 8 months ago) (4 children)

Why strictly less than 30 and greater or equal 25? (25 ≤ X < 30)

Shouldnt it be strictly less and strictly more (25 < X < 30)?

[–] [email protected] 7 points 8 months ago

And here comes the most annoying error, the off by one error

[–] [email protected] 7 points 8 months ago

I guess you could argue that people we refer to as "25 years old" are actually 25 years and some days/hours/minutes/whatever old, therefore more than 25. People referred to as 30 are, in the same vein, more than 30

[–] schmidtster 2 points 8 months ago* (last edited 8 months ago) (1 children)

Well if you’re 25 and a day, that would mean you wouldn’t be able to fit any definition. The second after you turn 25 you would be “over 25” and could be included in 25, over 25 and between 25 and X until you turn 26 and the same repeats.

[–] V0lD 1 points 8 months ago (1 children)

Even if you're 25 and 11 months, you should still be counted as 25. Same way it should be for other age based restrictions

[–] schmidtster 3 points 8 months ago* (last edited 8 months ago) (11 children)

But you’re not 25, you’re 25 and 11 months you can’t have your cake and eat it too.

If it’s the same way for other age base restrictions, you are now contradicting your original comments point… it’s between 25 to 30, so 25, 25 and a day, and 25 and 364 days would all be included.

[–] MeanEYE 3 points 8 months ago (3 children)

Unrelated question but why can't one have a cake and eat it? Presumably that's why you'd own a cake in the first place. Or is world filled with people eating other people's cakes but no owner is ever allowed to. Such a mysterious saying....

[–] schmidtster 2 points 8 months ago (1 children)

I’m an adult and go just drive and buy a cake anytime I want. I think it comes from you buy a cake to share, you are supposed to buy “a slice/piece” for yourself?

[–] MeanEYE 1 points 8 months ago (1 children)

I don't know but it doesn't make sense. The saying, that is.

[–] schmidtster 2 points 8 months ago (1 children)

Huh, it just clicked.

If you eat your cake you no longer have it, and to have a cake you can’t eat it.

[–] MeanEYE 1 points 8 months ago

Doesn't make a lot of sense to me still.

[–] DABDA 2 points 8 months ago (1 children)

The easiest way to parse the meaning is to reverse the statement order, i.e. "Can't eat your cake and have it too." If you ate it, you wouldn't have it. If you have it, you haven't eaten it. The two states are mutually exclusive.

[–] MeanEYE 1 points 8 months ago (1 children)

Okay, that makes sense, just weird choice of words.

[–] DABDA 3 points 8 months ago

Totally agree. I've never been a fan of the saying and it only clicked properly for me when I heard it explained with the statement reversal.

[–] [email protected] 1 points 8 months ago

That phrase is about fancy cakes, like wedding cake art. You can't keep the art and eat the cake. Like the food network cake competitions, some of those things are super creative, but you can't have the art and eat the cake.

It's like painting custom wrapping paper, or printing on toilet paper. If the purpose of something is to be consumed or destroyed, it can't do that and look good at the same time. You have to choose between having pretty mocha art and drinking a mocha.

load more comments (10 replies)
load more comments (1 replies)
[–] [email protected] 8 points 8 months ago

I'm going to laugh at this all day

[–] [email protected] 6 points 8 months ago (1 children)

THIS IS WHY YOU NEVER WRITE YOUR ENTIRE QUERY IN A SINGLE LINE

[–] Curdie 3 points 8 months ago (2 children)

As a c# mssql developer I'm not familiar with json or mongodb but I don't get the meme. What's wrong with this syntax? It's readable and relatively concise. Is this a whoosh moment for me? What am I missing?

[–] Pyroglyph 12 points 8 months ago* (last edited 8 months ago) (1 children)

It's a mess compared to the equivalent SQL.

SELECT *
FROM users
WHERE age >= 25 AND age &lt;= 30

I dislike SQL syntax more than most, and even I concede that SQL wins in this instance.

Edit: Not sure if this appears on all clients but the &lt; in the code block is meant to be a less-than symbol.

[–] ericbomb 4 points 8 months ago

There is no way I would ever get the amount of brackets right on that.

[–] Theharpyeagle 3 points 8 months ago

IMO it's just so clunky with what feels like way too many extraneous symbols. And that's just a very simple query, check out the equivalent of a join: https://stackoverflow.com/a/43653679

Granted, joining is not really what Mongo DB is for (that's the whole point of it being non-relational, after all). But even reaching deep into an object can get you into nesting hell very quickly.

[–] bullshitter 3 points 8 months ago (3 children)

I'm unfamiliar with the last comic where Jesus Christ is said. Does it mean he is happy with the result or can't bear to look at the result?

[–] themeatbridge 25 points 8 months ago

The OG comic was a guy talking to a baby, saying "Hey little guy, how's it going?" and the baby replies with gibberish. The third panel indicates a pause, and then the guy responds in the fourth panel with "yea" (which is supposed to be "yeah" and not the archaic affirmation that rhymes with "nay"). It's like he doesn't even know what he expected when he asked the question, and is just accepting the awkwardness and confusion.

The "Jesus Christ" variant seems to imply the stunning horror of whatever the guy sees in the second panel.

[–] [email protected] 6 points 8 months ago

He is horrified

[–] TryingToEscapeTarkov 1 points 8 months ago* (last edited 8 months ago)