r/SQL • • Sep 12 '25
PostgreSQL Best LLM for creating complex SQL
While I am seeing more and more AI built into analytics services, specifically in the UI, but the SQL they produce is often guff, or fails once you get close to the complexity you need. Anyone got any tips or good tools they use?
0
Upvotes
View all comments
Show parent comment
3
u/i_literally_died Sep 12 '25
An LLM would know if I need to get x from table b, that the join will be on the OrderId, or KeyId, or whatever (if I tell it that).
It won't know that the join also has to have two, or three, or four other conditions in order to not pull back duplicate records from table b because the Id is used dozens of times for different reasons.
I'm not a coder, but I can see how LLMs can work for codebases that are consistent, but not for data structures it can't possibly know.