Live data from Hacker News

Getting AI to write good SQL

cloud.google.com

61–70 of 379 posts

Re: Getting AI to write good SQL

#62

Earlier quoted context omitted.

It is absolutely the greatest golden age in programming ever - all these infinitely wealthy companies spending bajillions competing on who can make the best programming companion. Apart from the apologising. It's silly when the AI apologises with ever more sincere apologies. There should be no apologies from AIs.

companion or replacement?

... Or saboteur. :p

Re: Getting AI to write good SQL

#63

Earlier quoted context omitted.

Having proper constraints and foreign keys that are clear is generally all that's needed in my experience. Are you sure your tables have well defined constraints, so that the AI can be absolutely 100% sure how everything links up? SQL is very precise, but only if you're utilizing constraints and foreign key definitions well.

It’s BigQuery, so it likely won’t have any of these.

BigQuery supports all those SQL things I mentioned.

Re: Getting AI to write good SQL

#64
post #52

This is on howto to to write good SELECTS, not SQL. AI is good enough to also create schemas from spec, migrate, explore databases, testing etc which tgis article does not touch upon

Every time I've fed more than 5 migration files and asked Claude to make multiple across those files it fails, it does very badly in almost all cases, even on kinda basic schemas. I actually don't think LLMs grok complex migration files or sql that well at all.

Re: Getting AI to write good SQL

#66
post #35

> 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 S…

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

#67
All this LLM written SQL stuff sounds great until you realize if you don’t really know SQL you won’t be able to debug or fix any broken SQL an LLM generates.

Thus, this is mainly just a tool for true experts to do less work and still get paid the same, not a tool for beginners to rise to the level of experts.

Re: Getting AI to write good SQL

#69

Earlier quoted context omitted.

It’s BigQuery, so it likely won’t have any of these.

BigQuery supports all those SQL things I mentioned.

I’m just saying it’s likely they aren’t using them. But clearly you should if you want LLMs to do anything useful.

Re: Getting AI to write good SQL

#70

AI text to regex solutions would be incredibly handy.

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…

I use regex as an alternative to wildcards in various apps like notepad++ and vscode. The format is different in each app. And the syntax is somewhat different. I have to research it each time. And complex regex is a nightmare.

Which is why I would ask an AI to build it if it could.

Post reply on HN