Live data from Hacker News

Getting AI to write good SQL

cloud.google.com

241–250 of 379 posts

Re: Getting AI to write good SQL

#241

Can I just say that Google AI Studio with latest Gemini is stunningly, amazingly, game changingly impressive. It leaves Claude and ChatGPT's coding looking like they are from a different century. It's hard to believe these changes are coming in factors of weeks and months. Last month i could not believe how good Claude is. Today I'm not sure how I could continue programming without Google Gemini in my toolkit. Gemini…

I guess it depends on the type of tasks you give it.

They all seem to work remarkably well writing typescript or python but in my experience, they fall short when it comes to shell and more broadly dev ops

Re: Getting AI to write good SQL

#242
post #217

Earlier quoted context omitted.

Perhaps Perl has given me Stockholm Syndrome, but when I look at your escaped regex example, it's extremely natural for me. In fact, I'd say it's a little too simple, because the LLM forgot to exclude unnecessary whitespace: (REGEXP_MATCHES(commentary, '!\[\s*([^\]]*?)\s*\]\(\s*([^)]*?)\s*\)', 'g'))[2] AS src, (REGEXP_MATCHES(commentary, '!\[\s*([^\]]*?)\s*\]\(\s*([^)]*?)\s*\)', 'g'))[1] AS alt_text That is just nitp…

> As in, it does not take a lot learning time before you're faster than the LLM for 90% of things, and those things occur frequently enough that your "learning time deficit" gets repaid quickly. It doesn't matter how fast I get at regex, I still won't be able to type any but the shortest ( really good guesses about my vaguely worded intent. As for learning deficit: I am learning so much more thanks to heavy use of LL…

Good points. Also looking at your original example I noticed that not only humans can explain regularities they expect in many different ways (also correcting along the way), they can basically ask LLM to base the result on a reference. In your example you provided a template with an img tag and brackets having different attributes patterns. But one can also just ask for a html-style tag. As I did with the "Please create a regex for extracting image file names when in a text a html-style tag img is met" (not posting it here, but "src" is clearly visible in the answer). So the "knowledge" from other domains is applied to the regex creation.

Re: Getting AI to write good SQL

#243
post #167

Earlier quoted context omitted.

The current method of solving this is providing the AI with the documentation of the SDKs your code uses. Current LLMs have quite big context windows so you can feed them a lot of documentation. Some tools can even crawl multipage documentation and index them for the use of LLMs.

How do you do that practically/reliably? Would be great to just paste a link to the SDK Github repo, but doesn't seem to work (yet) in my experience

Where is also context7 mcp you could use, it does help sometimes

Re: Getting AI to write good SQL

#244
For me the flash model is way better than the pro model. I don't want to wait all the extra time to get some code back that I'm going to have to read and modify anyway. I much prefer getting a 92.5% right answer now, than 95% correct answer a minute or minutes from now.

Re: Getting AI to write good SQL

#245
post #212
post #161

Earlier quoted context omitted.

You're the one doing the gaslighting now. "It doesn't work for me, therefore it can't possibly work for anyone else."

Which is a very reasonable conclusion given the kinds of errors it makes. Why are you so defensive about the tech? Involved in any AI startups, perhaps?

Most of them are involved (including the latest round of YC startups), who have VCs invested in them to boost "AI agents" all over the internet and ignoring the laughable errors it makes.

Here are some headlines:

OpenAI explains why ChatGPT became too sycophantic [0]

Anthropic blames Claude AI for ‘embarrassing and unintentional mistake’ in legal filing [1]

xAI blames Grok’s obsession with white genocide on an ‘unauthorized modification’ [2]

So you see, these AI models can easily be prone to producing nonsensical errors unpredictably at any time.

[0] https://techcrunch.com/2025/04/29/openai-explains-why-chatgp...

[1] https://www.theverge.com/news/668315/anthropic-claude-legal-...

[2] https://techcrunch.com/2025/05/15/xai-blames-groks-obsession...

Re: Getting AI to write good SQL

#246
Can someone please answer these questions because I still think AI stinks of a false promise of determinable accuracy:

Do you need an expert to verify if the answer from AI is correct? How is it time saved refining prompts instead of SQL? Is it typing time? How can you know the results are correct if you aren't able to do it yourself? Why should a junior (sorcerer's apprentice) be trusted in charge of using AI? No matter the domain, from art to code to business rules, you still need an expert to verify the results. Would they (and their company) be in a better place to design a solution to a problem themselves, knowing their own assumptions? Or just check of a list of happy-path results without a FULL knowledge of the underlying design? This is not just a change from hand-crafting to line-production, it's a change from deterministic problem-solving to near-enough is good enough, sold as the new truth in problem-solving. It smells wrong.

Re: Getting AI to write good SQL

#247

Wait... people need AI to write SQL ?

A junior in SQL would need AI to write things they're not sure about, the same way stackoverflow has helped us for many many years before AI. A senior in sql, and in fact any languages, would use AI to be accelerated (I know I do).

Re: Getting AI to write good SQL

#248

Can someone please answer these questions because I still think AI stinks of a false promise of determinable accuracy: Do you need an expert to verify if the answer from AI is correct? How is it time saved refining prompts instead of SQL? Is it typing time? How can you know the results are correct if you aren't able to do it yourself? Why should a junior (sorcerer's apprentice) be trusted in charge of using AI? No ma…

Same reason as why it's harder to solve a sudoku than it is to verify its correctness.

Re: Getting AI to write good SQL

#249
A question: Does anyone know how well AI does generating performative SQL in years-old production databases? In terms of speed of execution, locking, accuracy, etc.?

I see the promise for green-field projects.

Re: Getting AI to write good SQL

#250

Can someone please answer these questions because I still think AI stinks of a false promise of determinable accuracy: Do you need an expert to verify if the answer from AI is correct? How is it time saved refining prompts instead of SQL? Is it typing time? How can you know the results are correct if you aren't able to do it yourself? Why should a junior (sorcerer's apprentice) be trusted in charge of using AI? No ma…

Same reason as why it's harder to solve a sudoku than it is to verify its correctness.

I should have made my post clearer :)

There isn't one perfect solution to SQL queries against complex systems.

A suduko has one solution.

A reasonably well-optimised SQL solution is what the good use of SQL tries to achieve. And it can be the difference between a total lock-up and a fast running of a script that keeps the rest of a complex system from falling over.

Post reply on HN