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/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.