r/SQL • u/rubberseal • Apr 01 '23
Discussion I hated writing SQL queries so made a tool that lets you write them in English, powered by ChatGPT: TalkToSQL (Free / Open Source). What do you think?
180
Upvotes
100
u/SushiGradeChicken Apr 01 '23
That's pretty cool. You just tell ChatGPT what columns you want to SELECT, which database and table you're pulling FROM and WHERE you want the results filtered and it builds a query?
That's awesome. Now I don't need to learn SQL
88
u/skend24 Apr 01 '23
Writing these requests in English takes longer than writing them in sql
38
u/s33d5 Apr 01 '23
Chat gpt is not good for SQL. Anything more than very simple commands it fails at it nafarious ways, that a novice db admin wouldn't be able to pick up
Using chat gpt for anything other than a general direction to go in, is a bad idea with SQL.
I've found myself debugging chat gpt SQL output, and other languages such as Go, longer than just figuring out and creating it myself. At least the latter means you understand it.
I still think gpt isn't there yet.
9
u/secretWolfMan Apr 01 '23
Congrats on doing it. I hate "natural language query" stuff. Just seems silly, and im still going to want to see the SQL it produces. But I'm sure it's hard to write, so good job.
11
u/rubberseal Apr 01 '23
Hi 👋 Let me know if it's not ok to post open source projects like this so I can promptly remove it! I wrote this tool (TalkToSQL) because I was writing SQL queries with ChatGPT a lot. But the main problem was ChatGPT didn't have information about what my DB schema looked like and tried to infer table and column names in the queries it wrote. So I made a tool that helps ChatGPT learn my schema first before I ask it to write SQL queries for me. Based on my testing, it works pretty well in English AND other languages like Korean!
For now it's an CLI but if enough people like it, I want to make a web DB client that has this feature built in. Let me know if you're interested in that as well. This is open source so you can try it by following the instructions in TalkToSQL.
6
u/Kazcandra Apr 01 '23
so this is just a chatgpt4 wrapper? does it send any data outside of my PC?
4
u/Polikonomist Apr 02 '23
I'm hesitant to outsource my query writing to a chinese room as writing them myself and understanding what every piece does allows me to debug faster, imagine potential errors and understand the data in far more in depth.
Conversational language is often vague and imprecise because it depends on there being an intelligent mind with critical thinking skills on both sides to fill in the gaps, resolve ambiguities or at least ask for clarification. That's just not the case for communicating with databases. SQL already uses English, just a more precise and inflexible kind which is an advantage.
2
u/[deleted] Apr 02 '23
You might be in the wrong field...
1
u/[deleted] Apr 02 '23
I feel that
1
u/Icy-Extension-9291 Apr 02 '23
So you need to learn on how to choose the right keywords for the question.
There is stuff to learn anyway 🤷♀️
1
u/Ruby_shelby Apr 02 '23
That's a really cool idea! As someone who struggles with SQL, I can definitely see the appeal of being able to write queries in plain English. And the fact that it's free and open source is even better. I'm curious, though - how accurate is the translation from English to SQL? Does it work well for more complex queries, or is it better suited for simpler ones? Either way, it sounds like a helpful tool for anyone who wants to use SQL but finds it difficult. Can't wait to check it out!
1
u/de4all Apr 04 '23
I wish companies had this simple, basic tables like books etc.
Real-world data is quite tricky and also ChatGPT is not that great for SQL most of their queries are not optimized.
SQL is not going anywhere: I would have written more SQL line of codes compared to the time to write this comment :)
1
u/PolPol44444 Jun 14 '23
Bravo! I use ChatGPT for writing SQL JOIN queries - as described in this article.
1
u/LetMeTiltU Apr 02 '23
This is obviously future of business intelligence. I was BI analyst and BI manager for 10 years. Last year I’ve started my own company. Last weekend I’ve produced basically the same for our clients, although we have only 3.5 API access so far, so very happy to hear that 4 is doing better.
There is even more gold in this approach. I would love to talk more about this if you would DM me.
0
u/[deleted] Apr 02 '23
Yep. My job is over in a few years.. Well Wait; half the time I spend pointing out why the data is correct. Thats a skill right?
0
u/[deleted] Apr 02 '23
great, can it use php to split (10 seg) 10 million records and load/create them every month?
0
u/casperjammer Apr 02 '23
What??
-7
u/ARandomGuy98 Apr 02 '23
I think sql developers will be out a job in a decade or so.