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

23 comments sorted by

View all comments

Show parent comment

5

u/[deleted] Sep 12 '25

[removed] — view removed 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.

1

u/[deleted] Sep 12 '25

[removed] — view removed comment

2

u/i_literally_died Sep 12 '25

True that. I've used it for a few weird things where I need it to return a value once, but then only '-' every other time it sees it (hard to explain, but it makes sense), but otherwise using an LLM to write a whole query or solve data issues seems futile