←back to thread

Getting AI to write good SQL

(cloud.google.com)
477 points richards | 8 comments | | HN request time: 0.882s | source | bottom
1. cloudking ◴[] No.44010100[source]
This is pretty simple in any foundation model, provide a well commented schema and ask for the query
replies(4): >>44010110 #>>44010243 #>>44010309 #>>44011095 #
2. tibbar ◴[] No.44010110[source]
Step 1: Your schema has thousands of tables and there aren't many comments.

Step 2...

replies(1): >>44010201 #
3. john2x ◴[] No.44010201[source]
Use AI to generate the comments of course
replies(1): >>44010381 #
4. fsndz ◴[] No.44010243[source]
the smolagents library is also pretty nice to do the scaffolding around the model. Text to sql seems simple in demos, but to make it work in real life complex cases is very hard: https://medium.com/thoughts-on-machine-learning/build-a-text...
5. quantadev ◴[] No.44010309[source]
I agree. There's really no magic to it any more. The table create DDL commands are a very precise description of the tables, so almost nothing more is ever needed. You can just describe in detail what query you need, and any decent LLM can do it just fine.
6. cloudking ◴[] No.44010381{3}[source]
Exactly, add any documentation you have about the app for more context too.
7. galenmarchetti ◴[] No.44011095[source]
there’s two kinds of people using AI to generate SQL…those who say it’s already solved and those who say it’ll be impossible to ever solve
replies(1): >>44013872 #
8. cloudking ◴[] No.44013872[source]
Yep, probably why I got upvoted then downvoted. I've been using LLMs to write SQL queries for 2 years.