News for hackers. Stuff that matters.
Re:Getting AI to write good SQL by tclancy on Friday May 16, 2025 @11:14PM (#44011775)
Mother of God. I can write JSON instead of a language designed for querying. What is the advantage? If I’m going to move up an abstraction layer, why not give me natural language? Lots of things turn a limited natural language grammar into SQL for you. What is JSON going to {do: for: {me}}?
Re:Getting AI to write good SQL by 8n4vidtmkvmk on Saturday May 17, 2025 @02:16AM (#44012372)
Sorry, I couldn't parse that. You didn't quote your keys
Re:Getting AI to write good SQL by tclancy on Saturday May 17, 2025 @08:10PM (#44017959)
Was on a phone. Also, there’s more invalid than that. Plus I am lazy.
Re:Getting AI to write good SQL by Spivak on Saturday May 17, 2025 @08:21AM (#44013758)
I find it funny people are making fun of this while every ORM builds up an object representing the query and then compiles it to SQL. SQL but as a data structure you can manipulate has thousands of implementations because it solves a real problem. This time it's because LLMs have an easier time outputting complex JSON than SQL itself.
Re:Getting AI to write good SQL by ses1984 on Saturday May 17, 2025 @11:11AM (#44014898)
Any idea why that is?
Re:Getting AI to write good SQL by ljm on Sunday May 18, 2025 @09:16AM (#44021201)
Something still has to convert the JSON to SQL but in this case, who is writing the JSON? An LLM?

Sometimes, it's easier or more efficient to just learn the shit you're working with instead of spending 1000x the compute fobbing it off to OpenAI. Even just putting a blob of SQL in a heredoc and using a prepared statement to parameterise it is good enough.

Beyond that, query building is just part of the functionality an ORM provides. The main chunk of it is the mapping of DB-level data structures to app-level models and vice-versa, particularly in an OOP context.