This is pretty simple in any foundation model, provide a well commented schema and ask for the query
Getting AI to write good SQL
51–60 of 379 posts
Re: Getting AI to write good SQL
#52Re: Getting AI to write good SQL
#53In real life I find using AI for SQL dangerous. It allows people that don't know what they do to write queries that can significantly impact servers. In my world databases are relatively big for most developers, but not huge. Sometimes when I want to fine tune a query I am challenging AI to provide a better solution. I give it the already optimized query and I ask for better. I never got a better answer, sometimes be…
This was my experience as well. However I have observed that things have been improving this regard. Newer LLMs do perform much better. And I suspect they will continue to get better over time.
Re: Getting AI to write good SQL
#54the short answer: use a semantic layer. It's the cleanest way to give the right context and the best place to pull a human in the loop. A human can validate and create all important metrics (e.g. what does "monthly active users" really mean) then an LLM can use that metric definition whenever asked for MAU. With a semantic layer, you get the added benefit of writing queries in JSON instead of raw SQL. LLM's are much…
Re: Getting AI to write good SQL
#55For the problems where it would matter the most, these tools seem to help the least. The hardest problem domains don't have just one schema to worry about. They have hundreds. If you need to spin up a personal blog or todo list tracker, I have no doubt that Google, et. al. can take you exactly where you want to go.
Re: Getting AI to write good SQL
#56the short answer: use a semantic layer. It's the cleanest way to give the right context and the best place to pull a human in the loop. A human can validate and create all important metrics (e.g. what does "monthly active users" really mean) then an LLM can use that metric definition whenever asked for MAU. With a semantic layer, you get the added benefit of writing queries in JSON instead of raw SQL. LLM's are much…
> you get the added benefit of writing queries in JSON instead of raw SQL. I’m sorry, I can’t. The tail is wagging the dog. dang, can you delete my account and scrub my history? I’m serious.
Re: Getting AI to write good SQL
#57Earlier quoted context omitted.
How do you validate it if you don’t know the syntax? Or are you saying that looking up syntax –> semantics is significantly quicker than semantics –> syntax? Which I don’t find to be the case. What takes time is grokking the semantics in context, which you have to do in both cases.
https://regex101.com/
Re: Getting AI to write good SQL
#58What’s the eventual goal of text to sql? Is it to build a copilot for a data analyst or to get business insight without going through an analyst? If it’s the latter - then imho no amount of text to sql sophistication will solve the problem because it’s impossible for a non analyst to understand if the sql is correct or sufficient. These don’t seem like text2sql problems: > Why did we hit only 80% of our daily ecommme…
> These don’t seem like text2sql problems: Correct, but I would propose two things to add to your analysis: 1. Natural language text is a universal input to LLM systems 2. text2sql makes the foundation of retrieving the information that can help answer these higher-level questions And so in my mind, the goals for text2sql might be a copilot (near-term), but the long-term is to have a good foundation for automating te…
Re: Getting AI to write good SQL
#59Earlier quoted context omitted.
This comment appears frequently and always surprises me. Do people just... not know regex? It seems so foreign to me. It's not like it's some obscure thing, it's absolutely ubiquitous. Relatively speaking it's not very complicated, it's widely documented, has vast learning resources, and has some of the best ROI of any DSL. It's funny to joke that it looks like line noise, but really, there is not a lot to learn to u…
Its something you use so sparingly far away usually that never sticks around
Re: Getting AI to write good SQL
#60Earlier quoted context omitted.
But “text to sql” isn’t an algorithm.
The processes the people want the sql for are likely filled with algo’s. An exec wants info in a known domain, set up a text to sql system with lots of context and testing to generate queries. If they think they have something good, get an expert to test and productionise it. “Thank you for your request. Can you walk me through the steps you’d use to do this manually? What things would you watch out for? What kind of…