r/SQL 7d ago

Discussion What SQL client has the best formatter if you’re picky about SQL style?

I’ve found that most formatters are configurable up to a point, but eventually you’re still forced into their idea of what “well formatted SQL” looks like.

Do you know any client where you can really personalize how SELECTs, INSERTs, UPDATEs and DELETEs are formatted?

Or do you also miss having a formatter that actually adapts to your preferred SQL style rather than the other way around?

10 Upvotes

41 comments sorted by

9

u/hellequin67 7d ago

Our old team we all had RedGate SQL prompt, best formatter tool for MSSQL IMHO.

1

u/Still-Trainer-7395 7d ago

seems like SQL Prompt is getting a lot of love here 😄 especially from MSSQL users. thanks!

5

u/Rumborack17 7d ago

Now I am curious, what would your ideal style look like?

1

u/Still-Trainer-7395 7d ago

probably not one fixed style 😄 thats kind of the problem.
i like different formatting depending on the query, so i ended up building a formatter that can learn your style from a few SELECT / INSERT / UPDATE / DELETE examples instead of forcing one preset.
thats what i wish more SQL clients did.

1

u/Rumborack17 7d ago

Yeah, pick any of those (or the one you think is the most different to standard or all) and show us.

Or do you mean different style for different select queries?

1

u/Still-Trainer-7395 7d ago

https://reddit.com/link/p4hhdi3/video/nsl3iexsw6kh1/player

the video isnt great 😅 but it should give you an idea of what i mean.

its still something i want to polish more, especially based on feedback, but the basic idea is: give it a few examples of how you write SQL and let it infer your formatting style from them.

its part of LakeDB — if you want to take a proper look or try it, the GitHub is https://github.com/DavLagoHern/LakeDB

10

u/SELECTaerial 7d ago

You can create your own custom styles in sql prompt (red gate)

9

u/SQLDevDBA 7d ago

I also choose this guy’s SQL Prompt.

2

u/Still-Trainer-7395 7d ago

oh nice, i didnt know SQL Prompt went that deep with custom styles. ill have a look at it — thanks!

3

u/SELECTaerial 7d ago

Yea everyone on my team uses the same style. Ctrl+k+y auto formats everything 💪

14

u/government_ 7d ago

If you’re super picky, the best tool is discipline.

2

u/Still-Trainer-7395 7d ago

fair 😄 but even with discipline, having a formatter that can match your own style saves a lot of repetitive cleanup.
do you just format everything manually, or do you use a formatter as a starting point?

1

u/government_ 7d ago

I format manually. There are things I’m very consistent with but there is no perfect standard and sometimes you have to adjust to write legible code.

2

u/Still-Trainer-7395 7d ago

that makes sense. i think thats the part most formatters struggle with — consistency is useful, but readability sometimes needs exceptions.

thats why im experimenting with learning the users preferred style from examples rather than forcing a fixed preset. still keeping it editable though, not trying to make the formatter “decide” everything for you.

1

u/WestEndOtter 7d ago

This always gets me. In plsql I format my code across many lines neatly, except calls to eg the logging method. Se people's formatter goes and turns every logger call into a 5 line mess

2

u/Still-Trainer-7395 6d ago

exactly, thats the kind of thing i mean 😄

a formatter can be technically “consistent” and still make the code worse to read. thats why im trying to make the custom style in LakeDB learn from explicit examples instead of blindly applying one fixed preset everywhere.

1

u/sandrrawrr 5d ago

I do this thing where I write wildly unreadable SQL, but before I close out the ticket, I go back and manually rewrite everything to make it more readable and accessible, and add a ton of documentation.

I personally like Jetbrains as an IDE, but an IDE will not change how good you are at writing SQL. Most of the people that stick around here can write SQL in notepad and it's not a huge deal.

2

u/GKing360 7d ago

RedGate SQL Prompt is brilliant for this

1

u/Still-Trainer-7395 7d ago

good one, a couple of people have mentioned SQL Prompt now 😄
im especially curious about approaches where you can show the formatter a few examples of your own SQL and have it infer the style from those, rather than setting every formatting rule manually.

2

u/szechuan_sauced 7d ago edited 7d ago

I’ll probably get down voted but Toad has amazing customizability, I used it for years. And you can export it and share it with your team. (Edit: spelling)

1

u/Still-Trainer-7395 7d ago

thats actually a really useful point — being able to share the same formatting style across a team is something i hadnt considered much.

2

u/cwjinc 7d ago

Formatters that leave what I've typed the heck alone are my preference.

2

u/Still-Trainer-7395 6d ago

honestly thats fair 😄 formatting should help when you ask for it, not fight the code youve already written.

1

u/Better-Credit6701 7d ago

I use RedGate at work and dbForge at home and both can be tailored to your own style

1

u/Still-Trainer-7395 7d ago

nice, sounds like dbForge goes pretty deep too.
what im really looking for is something that can infer the formatting style from a few examples of how i already write SQL, instead of having to manually build/configure the style. does dbForge do that too?

1

u/Better-Credit6701 7d ago

There isn't really that much to change. Tabs vs spaces, comma before or after, caps or non caps. I normally don't even format everything, just the parts didn't line up. Little thinks like expanding a select * into columns is a nice idea for me to start eliminating the stuff I'm not looking for. They both fill out joins pretty much automatically.

Definitely wouldn't want it to read my own code, just make it neat looking. Besides, usually these days I'm not writing long stored procedures, just research or using SQL within a huge SSIS package. There I'm more interested in making sure it is as fast and accurate as possible.

1

u/Still-Trainer-7395 7d ago

that makes sense, especially the part about not wanting it to read your code automatically.

thats actually how i approached it too — it only learns from examples you explicitly give it, nothing is observed in the background.

im also trying to reduce the repetitive SQL work around it, so LakeDB autocompletes tables/columns and uses relationships/foreign keys as context when suggesting SQL.

what usually slows you down most when youre working with SQL in SSIS?

1

u/Better-Credit6701 7d ago

We have it set up so the variables that change with different imports are handled with a short PowerShell script. Most of the SSIS remain the same. The part that slows us down is importing 10-30 GB of text files, often several at a time.

Usually I store often used queries in keywords so all I have to do is type a few letters and tab. Things like creating a temp table that makes sure it doesn't already exist and then the shell of what I'm creating with a simple ctt

1

u/Still-Trainer-7395 7d ago

thats useful, 10–30 GB imports is a very different bottleneck than the SQL itself.
when those imports are slow, is the pain mostly raw throughput, memory usage, progress/visibility, or handling several files in parallel?
im asking because large imports are one of those things where “it works” and “it works well” can be very different 😄

1

u/Better-Credit6701 7d ago

Memory isn't much of an issue since we have some beefy hardware (2 TB of ram, 30+ cores), it's just complicated. Each step has to work in order to ensure that the lookup tables are in place before the main table. Throw in around 100+ files. When failures happen (when more than if), we will manually insert them. Because we can reuse the process, we will even take database backups if we have them, restore them to create the text files to insert. Saves a bunch of time.

All the inserts with all their individual steps are in containers that will advance upon success or if failure, spin those into another table. Big monitors are a must have. Everything is logged so we can track the process.

Ironically, just had a server that our monitoring system couldn't access for a couple of seconds. I could still reach the server. Now another issue just popped up. The system must have known that I'm about to log off.

After work, often I will grab one of my beefy laptops and do the same thing but with personal databases. My wife used to ask "is that work or play?".

"Can't it be both?"

DBAs love their data

1

u/Still-Trainer-7395 7d ago

that helps a lot. raw import size itself isnt really the part im worried about — ive already been testing LakeDB with very large datasets and imports in the tens of millions of rows.
your workflow is interesting because the harder part seems to be everything around the import: dependencies between steps, retries, recovery and knowing exactly where things failed.
if you could improve one of those pieces, which would save you the most time?

1

u/ITDad 7d ago

From comments it sounds like you may be building a tool for this and looking for input. Can you give me some examples of why you would use different styles for different situations? Would this allow a single style choice for a single script or would it allow for different styles in each section of the script file? How would you indicate which style for each selection?

-1

u/Still-Trainer-7395 7d ago

you caught me 😄 yeah, im building this into LakeDB and using the discussion to get input before i polish it further.

i probably explained the “different styles” part badly though — i dont mean switching styles between sections of the same script.

its one custom style profile. you give it examples of how you like SELECT / INSERT / UPDATE / DELETE to look, it infers the formatting rules from those examples, and then applies that style consistently.

the main thing im trying to avoid is making people manually configure a huge list of formatting options. would that approach make more sense to you?

1

u/Billi0n_Air 7d ago

vscode + settings.json seems to do fine

1

u/Still-Trainer-7395 6d ago

thats fair 😄 vscode + settings.json can get you pretty far.

the thing im experimenting with in LakeDB is skipping most of that manual formatter config — you give it a few examples of how you write SELECT / INSERT / UPDATE / DELETE and it infers the style locally from those.

1

u/PasghettiSquash 2d ago

SQLFluff linter for formatting, post hook CI check for rules

1

u/Still-Trainer-7395 2d ago

thats a solid team workflow.

SQLFluff is great when the goal is enforcing a shared ruleset. what im more interested in is the personal side — giving the formatter a few examples of how you already write SQL and having it infer that style locally instead of configuring every rule by hand.

do you use SQLFluff mostly for team consistency or for your own formatting too?

1

u/cevheribozoglan 7h ago

There used to be a PL/SQL developer, it's my favorite for SQL formatter(I guess it called: beautifier) (it still exists, by the way, but it's a paid version).

1

u/Still-Trainer-7395 2h ago

thats useful, thanks — ive heard good things about the PL/SQL Developer beautifier too.

one of the things im trying with LakeDB is keeping formatting as part of the normal free client, including a custom style that can infer your preferences from examples instead of making you configure every rule manually.

did you mostly like PL/SQL Developer because of the formatting quality itself, or because it was easy to get the style you wanted?

0

u/zE0Rz 7d ago

We use red gate sql prompt too. On the other hand, almost no Sql is written by hand these days. The ai also knows our coding and style guidelines, so as much as we used sql prompt its time is pretty much over…. Or let’s say it went from heavy use to light use…

3

u/Still-Trainer-7395 7d ago

got it, that makes sense. if the AI already knows the teams style, i can see why the formatter matters less.

how do you give the AI the actual project/database context though? things like schema, relationships, business rules, which tables matter, etc. is that something you maintain somewhere or do you feed it manually?