28 ms·
Getting AI to write good SQL
- sgarland 1y agoGiven that their first query example has a leading wildcard as a predicate (WHERE p.product_name LIKE '%shoe%') and doesn't take case into account, I have doubts.
- rrrrrrrrrrrryan 1y agoYeah there's still a long way to go. Until these things actually try to consistently spit out SARGable queries, look at the query plans, check for covering indexes, etc. they're going to write worse queries than an entry level data engineer. I'm certain they'll get there soon, they're just not there yet.
- mritchie712 1y agothe 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 more consistent at writing a small JSON vs. hundreds of lines of SQL. We[0] use cube[1] for this. It's the best open source semantic layer, but there's a couple closed source options too. My last company wrote a post on this in 2021[2]. Looks like the acquirer stopped paying for the blog hosting, but the HN post is still up. 0 - https://www.definite.app/ https://www.definite.app/ 1 - https://cube.dev/ https://cube.dev/ 2 - https://news.ycombinator.com/item?id=25930190 https://news.ycombinator.com/item?id=25930190
- ljm 1y ago> 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.
- dangscientist 1y ago[flagged]
- fhkatari 1y agoYou move all the tools to debug and inspect slow queries, in a completely unsupported JSON environment, with prompts not to make up column names. And this is progress?
- deleted 1y ago[deleted]
- mritchie712 1y agoThe JSON compiles to SQL. Have you used a semantic layer? You might have a different opinion if you tried one.
- e3bc54b2 1y agoAs someone who actually wrote a JSON to (limited) SQL transpiler at $DAYJOB, as much fun as I had designing and implementing that thing and for as many problems it solved immediately, 'tail wagging the dog' is the perfect description.
- ljm 1y agoSELECT email FROM users WHERE deleted_at IS NOT NULL OR status = 'active' seems more semantic to me at first glance than piping this into a JSON->SQL library { "_select": "email", "_table": "users", "_where": { "deleted_at": { "_is": { "_not": SQL_NULL_VALUE } }, "_or": [ { "status": "inactive" }, ] } } which is usually how these things end up looking.
- indymike 1y agoThis may be the best comment on Hacker News ever.
- 1y ago
- galenmarchetti 1y agostill need someone to build the semantic layer, why not use text2sql or something similar for that
- tclancy 1y agoMother of God. I can write JSON instead of a language designed for querying. What is the advantage? If I’m going to move up an abstraction layer, why not give me natural language? Lots of things turn a limited natural language grammar into SQL for you. What is JSON going to {do: for: {me}}?
- 8n4vidtmkvmk 1y agoSorry, I couldn't parse that. You didn't quote your keys
- tclancy 1y agoWas on a phone. Also, there’s more invalid than that. Plus I am lazy.
- Spivak 1y agoI find it funny people are making fun of this while every ORM builds up an object representing the query and then compiles it to SQL. SQL but as a data structure you can manipulate has thousands of implementations because it solves a real problem. This time it's because LLMs have an easier time outputting complex JSON than SQL itself.
- ses1984 1y agoAny idea why that is?
- ljm 1y agoSomething still has to convert the JSON to SQL but in this case, who is writing the JSON? An LLM? Sometimes, it's easier or more efficient to just learn the shit you're working with instead of spending 1000x the compute fobbing it off to OpenAI. Even just putting a blob of SQL in a heredoc and using a prepared statement to parameterise it is good enough. Beyond that, query building is just part of the functionality an ORM provides. The main chunk of it is the mapping of DB-level data structures to app-level models and vice-versa, particularly in an OOP context.
- fkyimeanit 1y ago>you get the added benefit of writing queries in JSON instead of raw SQL You should have written your comment in JSON instead of raw English.
- meindnoch 1y ago>you get the added benefit of writing queries in JSON instead of raw SQL ^ kids, this is what AI-induced brainrot looks like.
- jinjin2 1y agoI agree that using a semantic layer is the best way to get better precision. It is almost like a cheatsheet for the AI. But I would never use one that forced me to express my queries in JSON. The best implementations integrate right into the database so they become an integral part of regular your SQL queries, and as such also available to all your tools. In my experience, from using the Exasol Semantic Layer, it can be a totally seamless experience.
- christophilus 1y agoA semantic layer would be great. It should be a structured layer designed to make relational queries easy to write. We could call it “structured data language” or maybe “structured query language”. In all seriousness, I have some complaints about SQL (I think LINQ’s reordering of it is a good idea), but there’s no need to invent another layer on order for LLMs to be able to wrangle it.
- cmrdporcupine 1y agoThe semantic layer for database queries is (roughly) the relational algebra.
- westurner 1y agoFrom "Show HN: We open sourced our entire text-to-SQL product" (2024) https://news.ycombinator.com/item?id=40456236 https://news.ycombinator.com/item?id=40456236 : > awesome-Text2SQL: https://github.com/eosphoros-ai/Awesome-Text2SQL https://github.com/eosphoros-ai/Awesome-Text2SQL > Awesome-code-llm > Benchmarks > Text to SQL: https://github.com/codefuse-ai/Awesome-Code-LLM#text-to-sql https://github.com/codefuse-ai/Awesome-Code-LLM#text-to-sql
- cloudking 1y agoThis is pretty simple in any foundation model, provide a well commented schema and ask for the query
- tibbar 1y agoStep 1: Your schema has thousands of tables and there aren't many comments. Step 2...
- fsndz 1y agothe 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-to-sql-agent-using-the-smolagents-library-c9e7f159c6cb https://medium.com/thoughts-on-machine-learning/build-a-text...
- quantadev 1y agoI 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.
- galenmarchetti 1y agothere’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
- mousetree 1y agoOut of all the AI tools and models I’ve tried, the most disappointing is the Gemini built into BigQuery. Despite having well named columns with good descriptions it consistently gets nowhere close to solving the problem.
- quantadev 1y agoHaving 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.
- flysand7 1y agoHaving written more SQL than any other programming language by now, every time I've tried to use AI to write the query for me, I'd spend way more time getting the output right than if I'd just written it myself. As a quick aside there's one thing I wish SQL had that would make writing queries so much faster. At work we're using a DSL that has one operator that automatically generates joins from foreign key columns, just like credit.CLIENT->NAME And you got clients table automatically joined into the query. Having to write ten to twenty joins for every query is by far the worst thing, everything else about writing SQL is not that bad.
- nashashmi 1y agoAI text to regex solutions would be incredibly handy.
- RadiozRadioz 1y agoThis 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 understand 90% of the expressions people actually write. It takes far longer to tell an AI what you want than to write a regex yourself.
- tough 1y agoIts something you use so sparingly far away usually that never sticks around
- skydhash 1y agoA cheat sheet is just a web search away.
- jimbokun 1y agoSo is an LLM.
- DonHopkins 1y agoSo is a real html parser. https://blog.codinghorror.com/parsing-html-the-cthulhu-way/ https://blog.codinghorror.com/parsing-html-the-cthulhu-way/ https://en.wikipedia.org/wiki/Beautiful_Soup_(HTML_parser) https://en.wikipedia.org/wiki/Beautiful_Soup_(HTML_parser)
- jacob019 1y agoThe first languge I used to solve real problems was perl, where regex is a first class citizen. In python less so, most of my python scripts don't use it. I love regex but know several developers who avoid it like plague. You don't know what you don't know, and there's nothing wrong with that. LLM's are super helpful for getting up to speed on stuff.
- tango12 1y agoWhat’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 ecommmerce transaction yesterday? > Why is customer acquisition cost trending up? > Why was the campaign in NYC worse than the same in SF?
- deleted 1y ago[deleted]
- mynegation 1y agoTo be fair, these don’t look like SQL problems either. SQL answers “what”, not “why” questions. The goal of text2sql is to free up analyst time to get through “what” much faster and - possibly- focus on “why” questions.
- cdavid 1y agoMy observation is the latter, but I agree the results fall short of expectations. Business will often want last minute change in reporting, don't get what they want at the right time because lack of analysts, and hope having "infinite speed" will solve the problem. But ofc the real issue is that if your report metrics change last minute, you're unlikely to get good report. That's a symptom of not thinking much about your metrics. Also, reports / analysis generally take time because the underlying data are messy, lots of business knowledge encoded "out of band", and poor data infrastructure. The smarter analytics leaders will use the AI push to invest in the foundations.
- phillipcarter 1y ago> 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 text2sql calls, comparing results, and pulling them into a larger workflow precisely to help answer the kinds of questions you're proposing. There's clearly much work needed to achieve that goal.
- AdrianB1 1y agoIn 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 because AI is hallucinating or because the changes that it proposes are not working in a way that is beneficial, it is like an idiot parrot is telling what it overheard in the brothel - good info if it is a war brothel frequented by enemy officers in 1916, but not these days.
- awesome_dude 1y agoMate, IME programmers who don't know what they are doing just do it anyways then look to blame someone/something else if things turn to custard. AI is just increasing the frequency of things turning to custard :)
- HideousKojima 1y agoAI is most effective as an accountability sink
- cheema33 1y ago> I give it the already optimized query and I ask for better. I never got a better answer.. 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.
- cjbgkagh 1y agoI’ve been working on highly optimized code that heavily uses CPU intrinsics, a year ago no chance, 6 months ago a helpful reference, today it’s a good starting point. That is an insane pace of improvement.
- ziml77 1y agoThe strategy I've used with these people is to let them prototype with AI and then have them hand over their work to me where I can then make it significantly more efficient. The nice thing is that their poor performing version acts as a reference for validating the output of my queries.
- wewewedxfgdf 1y agoCan 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 AI Studio is such a giant leap ahead in programming I have to pinch myself when I'm using it.
- insin 1y agoIs it just me or did they turn off reasoning mode in free Gemini Pro this week? It's pretty useful as long as you hold it back from writing code too early, or too generally, or sometimes at all. It's a chronic over-writer of code, too. Ignoring most of what it attempts to write and using it to explore the design space without ever getting bogged down in code and other implementation details is great though. I've been doing something that's new to me but is going to be all over the training data (subscription service using stripe) and have often been able to pivot the planned design of different aspects before writing a single line of code because I can get all the data it already has regurgitated in the context of my particular tech stack and use case.
- CuriouslyC 1y agoI think reasoning in the studio is gated by load, and at the same time I wasn't seeing so much reasoning in AIstudio, I was getting vertex service overloaded calls pretty frequently on my agents.
- energy123 1y agoThey rolled out a new model a week ago which has a "bug" where in long chats it forgets to emit the tokens required for the UI to detect that it's reasoning. You can remind it that it needs to emit these tokens, which helps, or accept that it will sometimes fail to do it. I don't notice a deterioration in performance because it is still reasoning (you can tell by the nature of the output), it's just that those tokens aren't in <think> tags or whatever's required by the UI to display it as such.
- rectang 1y ago> 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.
- hosel 1y agoReally? In my experience it’s been pretty good (using Pydantic)! I read over before I execute it, but it’s never done anything malicious.
- rectang 1y agoI 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.
- deleted 1y ago[deleted]
- yahoozoo 1y agoWhat is the relevance of Pydantic with SQL?
- deleted 1y ago[deleted]
- hsbauauvhabzb 1y agoExplain that to the average manager or junior engineer, both who don’t care about your desire to build well but not fast.
- 1y ago
- stefap2 1y agoI have done this using the OpenAI 4o model. I had to pass in a prompt with business-specific instructions, industry jargon, and descriptions of tables, including foreign keys. Then it would generate even complex join queries and return data. In my case, I was more interested in providing results to users not knowledgeable about SQL, but the SQL was displayed for information.
- leelou2 1y ago[dead]
- bob1029 1y agoFor 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.
- galenmarchetti 1y agoand then add in ambiguity in the business terms / intention behind the query. still a big need for something like semantic layer or ontology to sit between business and at least right now that stuff hasn’t been automated away yet (it should be though)
- mrtimo 1y agoMalloy [1] has a semantic layer [2]... and Model Context Protocol (MCP) support is being added through Publisher [3]. Something to keep an eye on. Seems like a great fit for LLMs. [1] https://www.malloydata.dev/ https://www.malloydata.dev/ [2] https://docs.malloydata.dev/documentation/user_guides/malloy_by_example https://docs.malloydata.dev/documentation/user_guides/malloy... [3] https://github.com/malloydata/publisher https://github.com/malloydata/publisher
- antman 1y agoThis 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
- TechDebtDevin 1y agoEvery 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.
- fooker 1y agoWell that's a great startup idea if you're familiar with the domain.
- benjbrooks 1y agoo3 has yet to fail me on complex, multi-table queries. Not a fan of BigQuery’s Gemini integration.
- LAC-Tech 1y agoIf LLMs are so wonderful we can just read from B+ Tree storage engines directly. SQL, ORMs, Query Planners... all bloat.
- bool3max 1y agogreat point
- deadbabe 1y agoAll 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.
- roywiggins 1y agoIt depends, sometimes just feeding back broken SQL with "that didn't return any rows, can you fix it" and it comes up with something that works. Or "you're looking at the wrong entity, look at this table instead" or whatever, without knowing how to write competent SQL. Obviously being able to at least read a bit of SQL and understanding the basic idea of relational databases helps loads.
- sgarland 1y ago> It depends, sometimes just feeding back broken SQL with "that didn't return any rows, can you fix it" and it comes up with something that works. But how do you know if the SQL is correct, or just happened to return results that match for one particular case?
- 1y ago
- gerdesj 1y ago[flagged]
- josephg 1y agoIf you know SQL, then yeah! But if you don't know SQL, using an AI to write a few queries & debug them is a great way to learn it. I'm pretty comfortable with sql but still found it a fabulous tool recently. I have a sql database which describes a tree of some ~600k events. Each event is in a session (via session_id). Most events have a parent event - and trees of events can involve multiple sessions. I wanted to add two derived columns to my events table. For each event, I wanted to name the root event for that event's tree and the root event within this session. I had code in typescript to do it - but unsurprisingly it was pretty slow. Well, it turns out you can write a recursive SQL query which can traverse the graph and populate those columns. I had no idea that was even possible. ChatGPT managed it pretty well - though I ended up making a bunch of tweaks to the query it suggested to simplify it. I learned a bunch of SQL in the process - and that was cool! Obviously I could have read the SQL documentation and figured it out myself, but it was faster & easier using chatgpt. Writing SQL queries is a fantastic use case for LLMs.
- deleted 1y ago[deleted]
- zxexz 1y agoI find Gemini excellent for sql. Wouldn’t consider myself an expert in many things, but in sql and database design id consider myself close. I like writing queries and doing the architecture, and that’s where it’s exceptionally helpful. The massive context length combined with pointed questions means i can just dump the entire DDL, and ask “what am i missing?”. It really is an excellent tool for helping with times like checks and catching dumb errors on complex databases.
- treebeard901 1y agoIf a lot of the value in a company is the software and over time a handful of AI companies start writing all the software, who really ends up owning all the value of the company?
- wheelerwj 1y agoThat’s easy. None of the value is in the software. The only value is in customers that use the software.
- treebeard901 1y agoSo again, no software, no customers, no value. Those who provide AI to create the software will eventually take the customers directly. At that point, many existing companies of all kinds will just sort of be an unncessary intermediary. It's not too different from how Amazon Basics monitored third party products sold on their site and eventually created a lower cost, often better product, to compete with them. Ultimately stealing their customers.
- dangus 1y ago> Even with a high-quality model, there is still some level of non-determinism or unpredictability involved in LLM-driven SQL generation. To address this we have found that non-AI approaches like query parsing or doing a dry run of the generated SQL complements model-based workflows well. We can get a clear, deterministic signal if the LLM has missed something crucial, which we then pass back to the model for a second pass. When provided an example of a mistake and some guidance, models can typically address what they got wrong. Sounds like a bunch of bespoke not-AI work is being done to make up for LLM limitations that point blank can’t be resolved.
- getgalaxy 1y ago[dead]
- levocardia 1y agoIn one of Stephen Boyd's lectures on convex optimization, he has some quip like "if your optimization problem is computationally intractable, you could try really hard to improve the algorithm, or you could just go on vacation for a few weeks and by the time you get back, computers will be fast enough to solve it." I feel like that's actually true now with LLMs -- if some query I write doesn't get one-shotted, I don't bother with a galaxy-brain prompt; I just shelve it 'til next month and the next big OpenAI/Anthropic/Google model will usually crush it.
- user3939382 1y agoTry getting it to write a codepen sim of 3 rectangles parallel parking.
- AbstractH24 1y agoHas the pace of this slown down or I have just lost track of the narrative? Feels like innovation in AI is rapidly changing from paradigm-shifting to incremental.
- owebmaster 1y ago> I just shelve it 'til next month and the next big OpenAI/Anthropic/Google model will usually crush it. 1 month to write some code with LLM, that's quite the opposite of the promised productivity gain
- th0ma5 1y agoExcept here the core functionality changes day to day and hinges on specific word usage.
- insin 1y agoIs it too late to rescue the phrase "one-shotted" or is it already too far gone, like "AI" and "agent"?
- IncreasePosts 1y agoCan't believe I'm seeing something from Google involving shoes but it isn't named gShoe.
- gitroom 1y ago[dead]
- zeroq 1y agoEvery once in a while I've been trying AI, since everyone and their mother told me to, so I comply. My recent endevour was with Gemini 2.5: - Write me a simple todo app on cloudflare with auth0 authentication. - Here's a simple todo on cloudflare. We import the @auth0-cloudflare and... - Does that @auth0-cloudflare exists? - Oh, it doesn't. I can give you a walkthrough on how to set up an account on auth0. Would you like me to? - Yes, please. - Here. I'm going to write the walkthrough in a document... (proceed to create an empty document) - That seems to be an empty document. - Oh, my bad. I'll produce it once more. (proceed to create another empty document) - Seems like you're md parsing library is broken, can you write it in chat instead? - Yes... (your gemini trial has expired, would you like to pay $100 to continue?)
- e3bc54b2 1y agoThe worse part is not even being trolled at AI roundabout. The worse part is gaslighting by people who then go on to imply that I'm dumb to not be able to 'guide' the model 'towards the solution', whatever the fuck that means. And this is after telling me that model is so smart to just know what I want. Claude and Gemini are pretty decent at providing a small and tight function definition with well defined parameters and output, but anything big and it starts losing shit left and right. All vibecoding sessions I've seen have been pretty dead easy stuff with lot of boilerplate, maybe I'm weird for just not writing a lot of boilerplate and rely on well-built expressive abstractions..
- floren 1y agoRemember, if AI couldn't solve your problem, you were probably using the wrong model. Did you try with o5-selfsuck-20250523-512B?
- kubb 1y agoIt’s brilliant because you can always shift the blame on the user. Wrong prompt, wrong model, should have used an agent and ran 3 models in parallel, etc. Meanwhile we get claims that the tools are as capable as a junior programmer, and CEOs believe that.
- neuroelectron 1y agoNo mention of knowing anything about the tables, versions or relational structure? Are we just assuming that's already given to the AI?
- curtisszmania 1y ago[dead]
- fourfun 1y agoGoogle may be getting AI to write good SQL, but they aren’t getting it to write good blog posts.
- gizmodo59 1y agoThe blog post lacks lots of details and sounds more of a marketing piece and “Try this!”. They did not release the evals, a very basic architecture flow which is not novel nor any real world benchmarks that says how it worked expect some vague statements. Must have been generated by Gemini
- danjc 1y agoThe article comments "out of the box, LLMs are particularly good at tasks like creative writing" but I think this actually demonstrates the problem with the ai. A writer won't think that they're good at creative writing. In fact, I'm pretty sure they'd think LLM's are terrible at creative writing. In other words, to an expert in their field, they're not that good - at least not yet. But to someone who is not an expert, they're unbelievably good - they're enabled to do something they had zero ability to do before.
- randomNumber7 1y agoYes, but why is then everyone on HN claiming LLMs can code on expert level?
- danjc 1y agoFast for hammering out boilerplate, great for understanding something you've never done before. Much less value for field-frontier or novel work.
- __loam 1y agoI would posit that most people on hackernews are actually not that experienced.
- candiddevmike 1y agoTechbro astroturfing. You don't really see the same level of OMG AI on other forums like Reddit. Same thing happened with cryptocurrencies, HN was inundated with plugs for them and the same behavior was downvoted severely elsewhere.
- jeltz 1y agoBecause the people claiming so are actually bad at coding. I suspect a lot of them actually work in non-coding positions. And while I can for sure see how LLMs can be useful, they code at the level of a junior dev fresh out of college, if I am being generous.
- 1y ago
- msvana 1y agoProblem no. 2 (Understanding user intent) is relevant not only to writing SQL but also to software development in general. Follow-up questions are something I had in mind for a long time. I wonder why this is not the default for LLMs.
- JodieBenitez 1y agoWait... people need AI to write SQL ?
- randomNumber7 1y agoMost people here have not understood the relational model, so yes.
- criddell 1y agoI’ve read most of Codd’s book on the subject and have written SQL on and off since the mid 90’s and I still need to look up the differences between the various joins anytime I use them.
- randomNumber7 1y agoOk, but you did get the general concept of why it is better than a hierarchical file storage system. I also assume you dont try to throw mongoDB on every problem where a SQL database is clearly superior.
- jeanloolz 1y agoA 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).
- JodieBenitez 1y agoI see this comparison too often and I don't think it's fair. Stackoverflow has peer review.
- jeanloolz 1y agoIt's a fair statement. Good point.
- 1y ago
- iddan 1y agoFor anybody wanting to use best-in-class AI SQL, I highly recommend checking out Sherloq (W23): https://www.sherloqdata.io/ https://www.sherloqdata.io/
- hakanito 1y agoThe game changer for me will be when AI stops hallucinating SDK methods. I often find myself asking ”show me how to do advanced concept X in somewhat niche Y sdk”, and while it produces confident answers, 90% of the time it is suggesting SDK methods that do not exist, so a lot of time is wasted just arguing about that
- M4v3R 1y agoThe 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.
- hakanito 1y agoHow 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
- jstummbillig 1y agoSimple way would be to use either Sonnet 3.7/5 or Gemini 2.5 pro in windsurf/cursor/aider and tell it to search the web, when you know an SDK is problematic (usually because it's new and not in the training set). That's all it takes to get reliably excellent results. It's not perfect, but, at this point, 90% hallucinations on normal SDK usage strongly suggests poor usage of what is the current state of the art.
- spariev 1y agoWhere is also context7 mcp you could use, it does help sometimes
- beala 1y agoYou can do this with Cursor. If your docs are at example.com, simply type "@example.com" and it will go read that webpage. I've even had luck simply dropping an entire OpenAPI spec into my repo and adding the file to the context window (also using the @ command).
- dcrimp 1y agoI wonder if, for a given dialect (and even DDL), you could use that token masking technique similar to how that Structured Outputs [1] thing went: Quote: "While sampling, after every token, our inference engine will determine which tokens are valid to be produced next based on the previously generated tokens and the rules within the grammar that indicate which tokens are valid next. We then use this list of tokens to mask the next sampling step, which effectively lowers the probability of invalid tokens to 0. Because we have preprocessed the schema, we can use a cached data structure to do this efficiently, with minimal latency overhead." I.e. mask any tokens that would produce something that isn't valid SQL in the given dialect, or further, a valid query for the given schema. I assume some structured outputs capability is latent to most assistants nowadays, so they probably already have explored this [1] https://openai.com/index/introducing-structured-outputs-in-the-api/ https://openai.com/index/introducing-structured-outputs-in-t...
- todotask2 1y agoThose days, we have many types of database tools—ORMs, query builders, and more. AI can help reduce the complexity and avoid lock-in to a specific tech stack. I love to write raw SQL.
- rawgabbit 1y agoRegarding the first issue: ” For example, even the best DBA in the world would not be able to write an accurate query to track shoe sales if they didn't know that cat_id2 = 'Footwear' in a pcat_extension table means that the product in question is a kind of shoe. The same is true for LLMs.” I wish developers would make use of long table names and column names. For example, pcat_extension could have been named release_schema_1_0.product_category_extension. And cat_id2 could have been named category_id2.
- mykowebhn 1y agoI understand from a technical POV how this could be considered great news. But I don't see how this is good news at all from a societal POV. The last 15 or so years has seen an unprecedented rise in salaries for engineers, especially software engineers. This has brought an interest in the profession from people who would normally not have considered SW as a profession. I think this is both good and bad. It has brought new found wealth to more people, but it may have also diluted the quality of the talent pool. That said, I think it was mostly good. Now with this game-changing efficiency from these AI tools, I'm sure we've seen an end to the glory days in terms of salaries for the SW profession. With this gone, where else could relatively normal people achieve financial independence? Definitely not in the service industry. Very sad.
- rocqua 1y agoSounds like there need to be measures to fix income inequality.
- foldr 1y agoSoftware engineers earning enough to achieve financial independence are generally employed by FAANG or (indirectly) by venture capitalists who have more money than they know what to do with. With all this money sloshing around, it takes only a little imagination to think of ways of channeling some of it to working people without employing them to write pointless (or in some cases actively harmful) software.
- zkry 1y agoIm curious why there's this sentiment in regarding advances in AI. High level programming languages didnt in the least bit take away the value of the SW profession, despite allowing a vast number more people to write software. The amount and complexity of software will expand to its very outer bounds for which specialists will be required.
- AbstractH24 1y agoA better comparison I think is low-code platforms. There are plenty of folks making a living using platforms like Salesforce and “clicks not code,” but it never led to an implosion of the SE job market. Just expanded the tech job pool. And it’s hard to imagine how that would have happened if everything needed to be coded. Like how a growth in medical-paraprofessionals didn’t negate the need for doctors and nurses.
- jgalt212 1y agoFor 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.
- pcblues 1y agoCan 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.
- herrkanin 1y agoSame reason as why it's harder to solve a sudoku than it is to verify its correctness.
- pcblues 1y agoI 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.
- raincole 1y agoThe number of solutions doesn't matter though. You can easily design a sudoku game that has multiple solutions, but it's still easier to verify a given solution than to solve it from scratch. It's not even about whether or not the number of solutions is limited. A math problem can have unlimited amount of proofs (if we allow arbitrarily long proofs), but it's still easier to verify one than to come up with one. Of course writing SQL isn't necessarily comparable to sudoku. But the difference, in the context of verifiability, is definitely not "SQL has no single solution."
- pcblues 1y agoA 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.
- sgarland 1y agoIt's very hit or miss. Claude does OK-ish, others less so. You have to explicitly state the DB and version, otherwise it will assume you have access to functions / features that may not exist. Even then, they'll often make subtle mistakes that you're not going to catch unless you already have good knowledge of your RDBMS. For example, at my work we're currently doing query review, and devs have created an AI recommendation script to aid in this. It recommended that we create a composite index on something like `(user_id, id)` for a query. We have MySQL. If you don't know (the AI didn't, clearly), MySQL implicitly has a copy of the PK in every secondary index, so while it would quite happily make that index for you, it would end up being `(user_id, id, id)` and would thus be 3x the size it needed to be.
- mark_l_watson 1y agoNice! A little off topic but I spent years experimenting writing AI-like natural language wrappers for relational databases that would query meta data to get column names, etc. Peter Norvig, in doing a tech review for me for the second edition of my Java AI book made a comment that the NLP database example was much better than anything else in the book, so the code I sweated over off and on for years was probably pretty good, BUT!, compared to what you can build with LLMs today, my old NLP wrappers aren't good at all. LLMs make some things that were difficult very easy now. Good article!
- jamesblonde 1y agoLLMs are still not great at generating SQL. If Google had a breakthrough, it should be on the bird brain benchmark - (A Big Bench for Large-Scale Database Grounded Text-to-SQLs) https://bird-bench.github.io/ https://bird-bench.github.io/ At the moment GCP are at 76%, humans are at 93%.
- tmpz22 1y agoIs it me or is the grammar of this article really poor: > If the user is a technical analyst or a developer asking a vague question, giving them a reasonable, but perhaps not 100% correct SQL query is a good starting point > Out of the box, LLMs are particularly good at tasks like creative writing, summarizing or extracting information from documents. I don't -think- this was written by an LLM, but it really pulls me out of the technical article.
- navaed01 1y ago“Metrics: We combine user metrics and offline eval metrics, and employ both human and automated evaluation, particularly using LLM-as-a-judge techniques”. I’m curious to know what people are doing to measure whether the customer got what they were looking for. Thumbs up/down seems insufficient to me. The ability of the LLM to perform purely depends on having good knowledge of what is going to get asked and how, which is more complex than it sounds What techniques are people having success with?
- edmundsauto 1y agoTraining a 2nd agent as a qualitative evaluator works pretty well "LLM-as-a-judge". You train it with labeled critiques from experts, iterate a few times, then point it to your ground truth human-labelled-data ("golden dataset"). The quantitative output metric is human2ai alignment on the golden dataset, mix that with some expert judgment about the critique output by the ai as well. Works pretty well for me, where you can typically get within the range of human2human variance.
- CommenterPerson 1y agoSQL Data analyst with years and years of experience here. Most of my roles were in small teams building quick ad-hoc analyses for business leaders in large multi billion dollar businesses. Example, one db was Oracle e-business suite. It had been set up ~20 years prior with enhancements along the way. There were only a handful of people in the company who knew what the fields helpfully named like ATTR_000349857. Everyone was overworked with urgent requests (and occasional layoffs) and no one bothered to spend time on documenting the database. I suppose this topic fits under "Provide business-specific context". Great, hire someone to understand and document all that crap. Ain't going to happen. The other roles also fit this pattern, different systems but urgent needs, always a drought of people who understood both the business and the database. Occasionally we'd get some "AI team" come looking for "data". After many mindless meetings with no clear objective except "increase profits", they'd quietly disappear. I use stack overflow a lot to pull SQL examples and tweak. A lot of AI talk feels like hype -- to start with, i'd suggest not redefining words like "hallucination", "intelligence" etc which mean something else in English. Maybe call it "advanced algorithms" and stop with the hype. Also the surveillance and extraction of user data for advertising. Thank you.
- senko 1y ago> Oracle e-business suite [...] set up ~20 years prior > fields helpfully named like ATTR_000349857 > Everyone was overworked > no one bothered to spend time on documenting the database. I can't blame AI for not being helpful here, nothing short of divine intervention can fix that.
- BohuTANG 1y ago[dead]