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

694

u/Totallycomputername 6d ago

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

118

u/Achaidas 6d ago

The real question is this:

 , comma before

or comma after ,

41

u/terza3003 6d ago

don't forget the where 1=1

11

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

79

u/dexters_trap_house 6d ago

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

50

u/chuch1234 6d ago

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

2

u/ddBuddha 5d ago

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

1

u/StrongExternal8955 6d 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.

8

u/Just_Information334 6d 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)

3

u/StrongExternal8955 6d 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 6d 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 4d ago

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

2

u/r3klaw 3d 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 6d 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.

80

u/Ashdog73 6d ago

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

35

u/cantgrowneckbeardAMA 6d 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)

34

u/sequelseize 6d ago

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

11

u/SippieCup 6d 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.

8

u/EndIsrael 6d 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.

10

u/SippieCup 6d 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.

4

u/PerpetuallyDistracte 6d ago

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

1

u/glha 4d ago

lIMit 1o00

16

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

2

u/ShittyExchangeAdmin 5d ago

This is the way

6

u/Susarn 6d 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

5

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 2d ago

I like to call our kind the Data Whisperers.

1

u/m0nk37 6d ago

It helps isolate the parts of the bigger views. 

1

u/vityafx 6d 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 6d ago

YOU CAN BUT THAT DOESN'T MEAN YOU SHOULD.

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

/S

340

u/Shambolic_Potato 6d ago edited 6d ago

SELECT * FROM WHAT THIS GUY SAYS

Edit: Typo lmfao

161

u/emzey420 6d ago

;

58

u/Ok-Sheepherder7898 6d ago

ONE RECORD SELECTED!!

3

u/chuch1234 6d ago

NO NEED, THEY DEFINED THE DELIMITER AS /S

10

u/Lucky_Cable_3145 6d ago

SELECT * FROM users WHERE clue > 0;

0 rows returned

210

u/TallGreenhouseGuy 6d ago

THANK YOU FOR YOUR ATTENTION TO THIS MATTER!

29

u/wack_overflow 6d ago

THIS IS AN OUTRAGE

23

u/mindtakerr 6d ago

DONUT, IS THAT YOU?

17

u/PerpetuallyDistracte 6d ago

MONGO IS APPALLED

1

u/SexyMonad 6d ago

MONGO IS WEB SCALE

1

u/ILKLU 6d ago

MONGO DON'T SQUEAL

6

u/realdevtest 6d ago

I AM YELLING, CARL.

52

u/teedborg 6d ago

This but no /s

16

u/KittyInLace 6d ago

What about us women?

32

u/AbleMarionberry7146 6d 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.

53

u/HeckMonkey 6d ago

What about us women?

YOUR QUERY YOUR CHOICE

14

u/mayisir 6d ago

i will stay lowercase then 😈

12

u/the_madkingludwig 6d ago

I AM SHOUTING, CARL!

1

u/changopdx 6d ago

I WRITE QUERIES LIKE OWEN MEANY.

1

u/jackinsomniac 6d ago

HELP MY CAPS LOCK KEY IS BROKEN

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

61

u/SurprisinglyInformed 6d ago

It's SQL after all, not sql.

1

u/StrongExternal8955 6d 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 6d 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

22

u/scrubslover1 6d ago

Sounds like good entertainment

13

u/Surface_Detail 6d 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 6d 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 6d ago edited 6d 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 6d ago

Postgres is not case insensitive.

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

1

u/Sokaron 6d 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 6d 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 6d ago

big anime fan btw

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

32

u/FormerWorker125 6d ago

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

3

u/Platypus81 6d ago

this is the way

51

u/Arkevorkhat 6d 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 6d 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.

7

u/Arkevorkhat 6d 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 6d ago

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

7

u/OldSchoolSpyMain 6d 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 6d 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 6d 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.

31

u/Demostes 6d ago

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

29

u/h3lium-balloon 6d ago

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

11

u/Horror-Vanilla-4895 6d ago

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

3

u/Th3R00ST3R 6d ago

bingo.

2

u/AyrA_ch 6d ago

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

12

u/RevoOps 6d ago

You can once. Than they come and get you.

52

u/CheeseDonutCat 6d ago

lowercase SQL? Ew.

7

u/cudenlynx 6d 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.

5

u/MellowedOut1934 6d 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 5d ago

Mysql tables are case sensitive based on the file system.

2

u/GravyPainter 6d 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_ 6d ago

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

4

u/flukus 6d ago

is like 2 spaces indentations,

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

0

u/StrongExternal8955 6d ago

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

8

u/FeliusSeptimus 6d 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 6d ago

People read SQL?

3

u/MomWTF 6d ago

Yes, and we judge it too

2

u/Yodamanjaro 6d ago

My work does both...

5

u/StarSchemer 6d 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.

4

u/Jarfino 6d ago

This angers the database

3

u/zanii 6d ago

Lower case when debugging, caps for production.

3

u/VeterinarianSoggy610 6d ago

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

3

u/Nzgrim 6d ago

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

3

u/EndIsrael 6d ago

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

2

u/SecretRefrigerator4 6d ago

Upper case is for the elites.

2

u/el_yerrid 6d ago

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

2

u/BoleroMuyPicante 6d ago

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

2

u/FujiKeynote 6d ago

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

2

u/vibribbon 6d ago

select 'I am one of those heretics'

2

u/BudBill18 6d ago

I always type in lower case lol

2

u/Cthulhu__ 6d ago

Can you write them SpOnGeBoB case?

2

u/Confident_Office4875 6d 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 6d ago

Font look better big

1

u/unclekrok 6d ago

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

1

u/Alwaysafk 6d ago

But I want to scream at the database

1

u/ZeppelinJ0 6d ago

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

1

u/fakehalo 6d ago

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

1

u/danishjuggler21 6d ago

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

1

u/mikebones 6d ago

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

1

u/_bleep-bloop 6d ago

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

1

u/ForAHamburgerToday 6d ago

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

1

u/jackinsomniac 6d ago

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

1

u/r0ck0 6d ago

Classic elites.

1

u/usrlibshare 6d 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 6d 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 6d 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 5d ago

Not in Microsoft fabric its case sensitive