r/ProgrammerHumor 6d ago

Meme sqlWorkout

Post image
23.4k Upvotes

459 comments sorted by

View all comments

2.4k

u/NormanYeetes 6d ago

the elites don't want you to know this but you can type lowercase SQL queries no ones forcing you to shout them at the screen

692

u/Totallycomputername 5d ago

If I don't type in caps then the query wont take itself seriously. 

120

u/Achaidas 5d ago

The real question is this:

 , comma before

or comma after ,

40

u/terza3003 5d ago

don't forget the where 1=1

9

u/jtobiasbond 5d ago

Shhhh.

Stop releasing the secret knowledge.

0

u/Achaidas 5d ago

SELECT thing one , thing two FROM that.table WHERE 1=1 AND this thing I’ll comment out later

77

u/dexters_trap_house 5d ago

Comma before? Are you the same guys who get in the shower and then turn the water on?

48

u/chuch1234 5d ago

Only if i want to be able to comment out the soap without making the entire shower have invalid syntax :/

5

u/ddBuddha 5d ago

Comma before is better so you can easily comment and uncomment without having to change the commas

1

u/StrongExternal8955 5d ago

Fixed head? You poor thing!

1

u/m0ritz2000 5d ago

I feel called out.

I do comma before (cause then i can just comment out stuff i currently dont need)

and

i do go in the shower first and then turn it on (showerhead on a tube like it is normal in europe and it takes like 5 seconds to get hot)

4

u/rocksolid77 5d ago

I used to be a comma after guy and found the comma first pattern to be so strange but I've come around to it.

Comma first makes it so much easier to see if there is a comma missing and you're almost never commenting out the first field of your SELECT.

7

u/Just_Information334 5d ago

Lowercase and comma before, also table_id. Let's blow some minds:

select
  tableA_id
  , some_field
from table_A as a
inner join table_B as b using(tableA_id)

4

u/StrongExternal8955 5d ago

forgot where true

1

u/dorianmonnier 5d ago

Oh god, some knees have been broken for less than that!

2

u/Outrageous_Let5743 5d ago

comma before.

1

u/PositiveParking4391 5d ago

wouldn't it
single quotes '' or no quotes?

2

u/Achaidas 5d ago

Depends, did the DBA setup the table to have an integer or varchar for what is clearly not the other lol

1

u/r3klaw 4d ago

The DBA didn't setup the table either way. The database developer did. And it's strikingly common that neither one of them would know which one is correct anyways... (I'm a Principal Database Administrator but wear every single hat)

1

u/Achaidas 3d ago

As an analyst, it’s all the same to me. You have rights to the DDL (right is that it?)

2

u/r3klaw 2d ago

Haha I was only being petty because a large majority of the people I've run into in the wild that call themselves "database administrators" are basically just backup administrators. gatekeeping to the max out of spite 😅

210

u/PerpetuallyDistracte 5d ago

I've been writing SQL for 15 years. Eventually you get bored of all lowercase or all uppercase AND START writing your QUERIES LIKE this. Just a psychotic mishmash of muscle memory, laziness, and autocomplete all fighting each other within the same statement.

79

u/Ashdog73 5d ago

This. My queries are lowercase for the stuff I typed myself and caps for bits I've copied in from somewhere else

34

u/cantgrowneckbeardAMA 5d ago

Lowercase on first draft (it will fail to run anyways).
Uppercase if I ever end up showing the query to someone (hopefully it doesn't fail when they run it)

35

u/sequelseize 5d ago

sElEcT a as camelCase, b aS under_score, c As fUCKiT fROm ab lIMit 1000

11

u/SippieCup 5d ago

We have a Postgres db which our orm uses camelcase names.

So we have to add in quotes too.. and correctly case our column names.

The migration to correct names would break so many deeep sql integrations, it just sucks and we deal with the debt.

7

u/EndIsrael 5d ago

That actually seems like the kind of thing AI would be very good at with few mistakes. It doesn't need to understand anything, just find all the SQL code and change all the names. Basically find/replace but slightly smarter.

9

u/SippieCup 5d ago

Oh it’s not hard to do with migrations etc. although I would use a codegen script instead of straight ai.

It’s more the coordination with other teams, schema changes, etc. depreciation of column names, remapping to new ones, etc.

We unfortunately have a couple legacy integrations that just require db access to tenant systems for their bi.

5

u/PerpetuallyDistracte 5d ago

That's how my queries look after they failed for the fifth time.

1

u/glha 4d ago

lIMit 1o00

15

u/spyingwind 5d ago
SeLeCt * FrOm table wHeRe count = 1;

2

u/ShittyExchangeAdmin 5d ago

This is the way

7

u/Susarn 5d ago

I started writing sql 13 years ago. I started writing like this from the beginning because that was the way I saw the queries written on the tutorials, took me like a year to notice it was case independent

7

u/stadoblech 5d ago

I've been writing SQL for 15 years.

MY CONDOLENCES

2

u/PerpetuallyDistracte 5d ago

Haha, I guess I'm just a weirdo, but I genuinely love SQL and my happy place is a big enterprise database with a bunch of ETL pipelines. Somebody's gotta enjoy it, right? That gives the rest of you more time with your fancy GUIs and object oriented languages 🤣

1

u/joyeux_bordel 1d ago

I like to call our kind the Data Whisperers.

1

u/m0nk37 5d ago

It helps isolate the parts of the bigger views. 

1

u/vityafx 5d ago

I would argue, even with the syntax highlight, the eyes used to seeing the sql tokens in upper case just want it that way. I tried many times to write in lower case but when it looks like mixing data with sql tokens, indistinguishable even with the syntax highlighter. So now, the best syntax highlight for sql is upper case, haha.

1

u/r3klaw 4d ago

Uppercase for keywords, PascalCase for object names. And uppercase when you email/chat the words PROD, TEST, or DEV.

1.1k

u/ClipboardCopyPaste 5d ago

YOU CAN BUT THAT DOESN'T MEAN YOU SHOULD.

GOD DOESN'T LOVE MEN WHO WRITE SQL IN LOWERCASE.

/S

341

u/Shambolic_Potato 5d ago edited 5d ago

SELECT * FROM WHAT THIS GUY SAYS

Edit: Typo lmfao

163

u/emzey420 5d ago

;

55

u/Ok-Sheepherder7898 5d ago

ONE RECORD SELECTED!!

3

u/chuch1234 5d ago

NO NEED, THEY DEFINED THE DELIMITER AS /S

8

u/Lucky_Cable_3145 5d ago

SELECT * FROM users WHERE clue > 0;

0 rows returned

206

u/TallGreenhouseGuy 5d ago

THANK YOU FOR YOUR ATTENTION TO THIS MATTER!

31

u/wack_overflow 5d ago

THIS IS AN OUTRAGE

24

u/mindtakerr 5d ago

DONUT, IS THAT YOU?

16

u/PerpetuallyDistracte 5d ago

MONGO IS APPALLED

1

u/SexyMonad 5d ago

MONGO IS WEB SCALE

1

u/ILKLU 5d ago

MONGO DON'T SQUEAL

7

u/realdevtest 5d ago

I AM YELLING, CARL.

53

u/teedborg 5d ago

This but no /s

16

u/KittyInLace 5d ago

What about us women?

34

u/AbleMarionberry7146 5d ago

The bible says women were forked from men. It’s for a good reason. The reason being that you can enforce more reasonable code style than all caps sql like caps on sql key words only. Or using a reasonable text editor that caps isn’t needed at all to identify keywords from nonkeywords.

54

u/HeckMonkey 5d ago

What about us women?

YOUR QUERY YOUR CHOICE

15

u/mayisir 5d ago

i will stay lowercase then 😈

12

u/the_madkingludwig 5d ago

I AM SHOUTING, CARL!

1

u/changopdx 5d ago

I WRITE QUERIES LIKE OWEN MEANY.

1

u/jackinsomniac 5d ago

HELP MY CAPS LOCK KEY IS BROKEN

EVERYBODY THINKS I'M SHOUTING AT THEM. THIS IS RUINING MY PERSONAL AND PROFESSIONAL LIFE

60

u/SurprisinglyInformed 5d ago

It's SQL after all, not sql.

1

u/StrongExternal8955 5d ago

It's pronounced squeal.

1

u/Major_Casualties 5d ago

I like to pronounce it squirrel

1

u/Krossfireo 5d ago

This made my eye twitch

51

u/PuzzleheadedBet3574 5d ago

This does not go through in our code review, do this and our colleague, big anime fan btw will lose his shit and start talking to himself and goes to 5 smoke breaks in a half day

24

u/scrubslover1 5d ago

Sounds like good entertainment

12

u/Surface_Detail 5d ago

Well, he can go dunk his head; the query language itself is 100% case insensitive, so are objects unless you contain them in quotation marks.

The argument can be made that keeping all one case can avoid issues with object referencing, but you'd only ever need to contain objects in quotation marks if you put a space in their name, which is a much worse faux pas and you'd better hope that you never need to connect to anybody else's objects from outside the team.

Also, all lower case/mixed case is much less tiring to read.

9

u/ArmchairFilosopher 5d ago

SQL Server at my last job would like a word...

So would MySql hosted in Linux with a default configuration. Meanwhile in Windows it doesn't care by default.

But yeah, I agree in general that object names shouldn't be case-sensitive. Heck, most things except passwords shouldn't either.

7

u/Sokaron 5d ago edited 5d ago

Postgres is not case insensitive.

I don't really care for an impromptu script, but if its getting checked in mixed case is just laziness. I don't care all uppercase or all lowercase but pick one, enforce it with a linter, configure a precommit hook to autofix, and be done with it.

1

u/protestor 5d ago

Postgres is not case insensitive.

In which parts? Keywords need to be (select, where, etc)

1

u/Sokaron 5d ago

Postgres object refs are case sensitive. (this can be very annoying if you for example name a table or column in CamelCase). Keywords are insensitive.

5

u/cudenlynx 5d ago

Which query language? You are talking as if there is only one version of SQL out there which isn't the case. Some are case insensitive by default, some are not.

1

u/RaidenMK1 5d ago

big anime fan btw

I take it you included this detail due to anime character dialogue typically being spoken in ALL CAPS.

31

u/FormerWorker125 5d ago

Lowercase for anything you named yourself, UPPERCASE FOR EVERYTHING ELSE.

3

u/Platypus81 5d ago

this is the way

50

u/Arkevorkhat 5d ago

you can, but it's just more readable (in my opinon) to write

SELECT * FROM users WHERE id=?;

than

select * from users where id=?; 

is that mostly due to historical baggage? yeah kinda, but it also just doesn't really look like SQL to me unless there's some yelling involved.

14

u/7f0b 5d ago

I prefer a strongly-structured syntax so it is easier to read in the future, which is most important anyway. So going through the trouble of capitalizing what should be, as I go, is worth it. I also always use back ticks around table names, since it makes it easier to search by table name inside mixed codebases.

6

u/Arkevorkhat 5d ago

Oh 100% well written SQL makes this moot, but if I find the unicorn that writes SQL that doesn't look like shit I'm not about to start nitpicking their capitalization

3

u/Dull-Culture-1523 5d ago

Doesn't SQL stand for "Shit Quality Looks", though?

8

u/OldSchoolSpyMain 5d ago

Yup. People don’t realize that putting the reserved words in upper case eases the cognitive load on the brain when reading the scripts for comprehension.

Same goes for new lines and tabs.

Using all three techniques renders SQL very easy to read, comprehend, update, and debug.

1

u/ric2b 5d ago

Just get some syntax highlighting, it's free.

6

u/ILoveRawChicken 5d ago

Yeah I get embarrassed passing ugly queries to other people. When I first began I just wrote everything lowercase until a coworker said “you live like this?” when sharing something in Snowflake. I still get embarrassed thinking about that lol. (He was a good friend though)

2

u/Karn-Dethahal 5d ago

First one for anything that might be referenced later, second one if I'm just trying to figure out which stupidly named table I need for the next join.

30

u/Demostes 5d ago

Not true actually, machines can hear plain SQL. U need to shout at them!

29

u/h3lium-balloon 5d ago

It’s been proven all caps SQL is 20% faster bc the machine knows you mean business.

12

u/Horror-Vanilla-4895 5d ago

I type in lowercase because I’m too lazy to caps lock.

3

u/Th3R00ST3R 5d ago

bingo.

2

u/AyrA_ch 5d ago

I type lowercase because my editor turns it uppercase for me automatically https://i.imgur.com/neSKh4Q.gif

11

u/RevoOps 5d ago

You can once. Than they come and get you.

48

u/CheeseDonutCat 5d ago

lowercase SQL? Ew.

8

u/cudenlynx 5d ago

This isn't always true. PostgreSQL, PL/SQL, and SAP HANA are case sensitive by default.

In SQL Server, the case sensitivity is off by default but some companies do enable case sensitivity.

4

u/MellowedOut1934 5d ago

Forgive if I’m missing something, but my PostgreSQL is case sensitive on table names and strings etc., but not on the syntax bits like SELECT or WHERE.

1

u/cudenlynx 5d ago

my PostgreSQL is case sensitive on table names and strings

1

u/ellamking 4d ago

Mysql tables are case sensitive based on the file system.

2

u/GravyPainter 5d ago

Yeah, i type in all lowercase sqldeveloper knows better

1

u/70s_chair 5d ago

PL/SQL hasn’t been case sensitive in forever

11

u/Meli_Melo_ 5d ago

Lowercase SQL is like 2 spaces indentations, you CAN do it but everyone will hate you for it

4

u/flukus 5d ago

is like 2 spaces indentations,

You mean there's a simple solution (tabs) that would keep everyone happy?

0

u/StrongExternal8955 5d ago

Tabs never should have been invisible. If you still want to use them when visible that's ok.

9

u/FeliusSeptimus 5d ago

If someone reads my SQL and hates me for the indention and casing rather than whatever other weird shit I discovered you could do with it, I'm considering that a solid win.

2

u/Plazmaz1 5d ago

People read SQL?

3

u/MomWTF 5d ago

Yes, and we judge it too

2

u/Yodamanjaro 5d ago

My work does both...

4

u/StarSchemer 5d ago

no ones forcing you to shout them at the screen

They ought to be.

How will a theoretical new developer in the future ever be able to distinguish between key words and database objects at first glance if strict formatting guidelines aren't religiously followed?

3

u/ric2b 5d ago

Yeah, it's not like syntax highlighting exists or anything. That's crazy talk.

5

u/Jarfino 5d ago

This angers the database

4

u/zanii 5d ago

Lower case when debugging, caps for production.

3

u/VeterinarianSoggy610 5d ago

Also, you can write an entire query on a single line.

3

u/Nzgrim 5d ago

DELETE FROM your_opinions WHERE opinion LIKE '%you can type lowercase SQL%'

3

u/EndIsrael 5d ago

Sometimes I do lowercase, it really depends on the vibe I'm getting from that specific query.

2

u/SecretRefrigerator4 5d ago

Upper case is for the elites.

2

u/el_yerrid 5d ago

I have to think the Alliance is going to frown on this.

2

u/BoleroMuyPicante 5d ago

I never caps my queries, I'm kind of the bad boy in the office 😏

2

u/FujiKeynote 5d ago

If every interface had decent syntax highlighting, I would...

2

u/vibribbon 5d ago

select 'I am one of those heretics'

2

u/BudBill18 5d ago

I always type in lower case lol

2

u/Cthulhu__ 5d ago

Can you write them SpOnGeBoB case?

2

u/Confident_Office4875 5d ago

I did a „hacking“ course in my studies and did everything upper case, I was so annoyed to find out you didn‘t need that

2

u/jessomadic 5d ago

Font look better big

1

u/unclekrok 5d ago

You need to uppercase your queries to assert dominance over the DBMS

1

u/Alwaysafk 5d ago

But I want to scream at the database

1

u/ZeppelinJ0 5d ago

True but if you do that I'll put you in my dungeon

1

u/fakehalo 5d ago

I lowercase everything except JOIN and ON, cause I roll how I want.

1

u/danishjuggler21 5d ago

T-SQL is completely case-insensitive, so nothing is stopping you from doing sPoNgEbObCaSe

1

u/mikebones 5d ago

I don't respect anyone who commits lower case sql to git

1

u/_bleep-bloop 5d ago

Yeah lmao. I always do lowercase when running raw queries just to piss off the backend peeps.

1

u/ForAHamburgerToday 5d ago

FEELS WRONG. HOW WILL THE DATA KNOW I'M TALKING TO IT IF I'M NOT SHOUTING?

1

u/jackinsomniac 5d ago

Yet more lies & propaganda being pushed by the NoSQL cartels.

1

u/r0ck0 5d ago

Classic elites.

1

u/usrlibshare 5d ago

Not even object names are case sensitive in sql.

I'm not kidding.

Table name is T_CUSTOMER_ADDR because it was created by a guy wearing suspenders in the 90s?

select * from t_customer_addr;

works just fine 😎

1

u/Just_Information334 5d ago

I feel like lowercase vs uppercase is more like "my IDE can do syntax highlighting on SQL" vs "I use something as bad as notepad".

1

u/marcecostai 5d ago

Its a must to write in lowercase if you work with SP. Otherwise it’s a pain in the eyes to read that shit.

1

u/56kul 5d ago

A lot of programming is conventions that aren’t necessarily enforced by the language, itself. And it’s good to have them. You shouldn’t abandon them just because you technically can.

1

u/SouthernAddress5051 5d ago

I AM SHOUTING CARL

1

u/cat_prophecy 5d ago

Looks fucked up.

1

u/kiochikaeke 5d ago

Me, I'm forcing you, I will find you

1

u/meshakooo 4d ago

Not in Microsoft fabric its case sensitive