News for hackers. Stuff that matters.
Re:Getting AI to write good SQL by rectang on Friday May 16, 2025 @08:04PM (#44010899)
> We will cover state-of-the-art [...] how we approach techniques that allows the system to offer virtually certified correct answers.

I don't need AI to generate perfect SQL, because I am never going to trust the output enough to copy/paste it — the risk of subtle semantic errors is too high, even if the code validates.

Instead, I find it helpful for AI to suggest approaches — after which I will manually craft the SQL, starting from scratch.

Re:Getting AI to write good SQL by hosel on Friday May 16, 2025 @09:00PM (#44011204)
Really? In my experience it’s been pretty good (using Pydantic)! I read over before I execute it, but it’s never done anything malicious.
Re:Getting AI to write good SQL by rectang on Friday May 16, 2025 @09:10PM (#44011259)
I don't trust myself to craft a prompt in natural language which completely specifies my intent as codified with the precision of a programming language.

I also tend to turn to AI for advising me on difficult use cases, and most of the time it's for production code rather than one-offs. The easy cases, I just write myself because it's more mental effort to review code for subtle errors than it is to write it.

Re:Getting AI to write good SQL by yahoozoo on Saturday May 17, 2025 @07:16AM (#44013480)
What is the relevance of Pydantic with SQL?
Re:Getting AI to write good SQL by hsbauauvhabzb on Friday May 16, 2025 @09:36PM (#44011379)
Explain that to the average manager or junior engineer, both who don’t care about your desire to build well but not fast.
Re:Getting AI to write good SQL by rectang on Friday May 16, 2025 @11:14PM (#44011772)
It’s not true that I want to build “well but not fast” — I’m trying to add value, and both speed and reliability matter. My productivity is high and I don’t have trouble articulating why; my approach has generally (though not universally) been well received by management and colleagues.
Re:Getting AI to write good SQL by noosphr on Friday May 16, 2025 @09:51PM (#44011448)
> So now that we brought down prod for a day the new rule is no AI sql without three humans signing off on any queries.
Re:Getting AI to write good SQL by Closi on Friday May 16, 2025 @09:57PM (#44011475)
If that’s the scenario, I would be asking why the testing pipeline didn’t catch this rather than why was the AI SQL wrong.
Re:Getting AI to write good SQL by noosphr on Friday May 16, 2025 @10:31PM (#44011595)
Because the testing pipeline isn't the real database.

Anyone that knows a database well can bring it down with a innocent looking statement that no one else will blink at.

Re:Getting AI to write good SQL by Closi on Sunday May 18, 2025 @05:06AM (#44020014)
Sure, but everyone knows humans end up bringing down the database too by writing an innocent looking test query nobody else blinks at, which is why you end up needing a testing strategy for ANY SQL before YOLO'ing into prod.
Re:Getting AI to write good SQL by fkyimeanit on Friday May 16, 2025 @11:28PM (#44011821)
Because the testing pipeline was generated by AI, and code-reviewed by AI, reading a PR description generated by AI.
Re:Getting AI to write good SQL by dns_snek on Saturday May 17, 2025 @09:35AM (#44014227)
To offer a 3rd option - what testing pipeline? Incompetent managers aren't going to approve of developers "wasting their time" on writing high quality tests.
Re:Getting AI to write good SQL by paulddraper on Friday May 16, 2025 @09:48PM (#44011432)
Hopefully your trust in yourself is warranted
Re:Getting AI to write good SQL by rectang on Friday May 16, 2025 @11:01PM (#44011729)
I embrace my fallibility, and enthusiastically pursue testing, code reviews, staging environments, and so on to minimize the mistakes that make it through to production.

It seems to me that this skeptical mindset is consonant with handling AI output with care.

Re:Getting AI to write good SQL by auggierose on Saturday May 17, 2025 @01:53AM (#44012314)
You'd rather trust in AI than yourself?
Re:Getting AI to write good SQL by malthaus on Saturday May 17, 2025 @02:14AM (#44012366)
in writing good sql code? i definitely would

ai is not going to replace the senior sql expert with 20 years of battle experience in the short-term but support me who last dug into sql 15 years ago and needs to get a working sql query in a project. and ai usually does a better job than me copy pasting googled code in between quickly browsing through tutorials.