r/SQL • • Sep 09 '26

Discussion How much SQL do you still write manually?

With AI getting better at writing SQL, I’ve been wondering how much SQL analysts actually write from scratch these days.
Do you still write most of your queries manually, or do you use AI for things like joins, CTEs, debugging, optimization, etc.?
And has your use of AI actually changed how much SQL you need to know?

115 Upvotes

240 comments sorted by

View all comments

Show parent comment

3

u/NawMean2016 Sep 09 '26

Alright I'll hear you out. Elaborate?

-1

u/Thadrea Data Science Manager Sep 09 '26

Elaborate on what, exactly? 200-line queries are typically an unmaintainable mess.

There are many situations where you need 200+ lines of logic to implement a specific set of requirements, yes. A well-managed codebase would separate those 200+ lines into smaller chunks that are individually understandable, versioned and diff-able.

Putting it all into one monster query is a serious anti-pattern and I'm not going to pretend that it isn't--Not only is it bad for the developers but it also bad for the database. Query planners necessarily get less and less effective at optimizing the tasks put to them the more and more convoluted a query gets.

3

u/geek180 Sep 09 '26

I agree with your comment on breaking out logic into multiple pieces, and avoiding extremely long complex queries, but 200 lines is really not that long, especially if you are using CTEs for everything.

0

u/Thadrea Data Science Manager Sep 10 '26

That's kinda the point... you shouldn't be using CTEs for everything.

You should be using temp tables in a lot of those cases and views in many of the others.

Long strings of nested CTEs are literal spaghetti code.

1

u/geek180 Sep 10 '26

I disagree, at least for what I work on. We are a dbt-heavy shop within snowflake and in that context, there’s little reason for the temp tables and chained CTEs are not only extremely easy for anyone to follow and read, but also perform practically the same as any other kind of query.

We also have 1000+ dbt models (mostly views) as it is, so I’m constantly assessing others’ work to find ways to consolidate logic into fewer models. Sometimes that means having a longer chain of CTEs in a single file.