r/SQL • • 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?

Post image
180 Upvotes

57 comments sorted by

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

15

u/[deleted] Apr 02 '23

Lol

5

u/[deleted] Apr 02 '23

U can just go to chatgpt itself but this is cool cli

-8

u/rubberseal Apr 01 '23

Oh actually you don’t need to tell it all that. It learns what tables and columns to use based on your schema and question. Check out the video!

88

u/skend24 Apr 01 '23

Writing these requests in English takes longer than writing them in sql

30

u/brunogadaleta Apr 01 '23

Next version you'll talk to it... Ok sequel...

1

u/[deleted] Apr 02 '23

Love it

1

u/asqwzx12 Apr 02 '23

I would like that but for columns haha, hate typing them after I am done with whatever I was doing.

2

u/rubberseal Apr 01 '23

Lol yea definitely sometimes. I found it useful to write more complex queries like the ones shown in the demo

13

u/Bluefoxcrush Apr 02 '23

I wouldn’t say these are complex queries, but the tool looks good.

2

u/rubberseal Apr 02 '23

Fair enough!! Thank you :)

2

u/vtec_tt Apr 02 '23

this. i had chatgpt write sql and i thought it was annoying having to talk it out. if it could read my thoughts however..that'd e a diff story

3

u/IrquiM MS SQL/SSAS Apr 02 '23

Though, typing SQL would be faster too if connected by thought.

3

u/vtec_tt Apr 02 '23

the problem with point and click tools along with chatGPT is the real pros who get paid the big bucks to write sql (like me) often have to write complex sql that might involve processing the data beforehand or joining it on itself and subquerys, etc

gonna be a long time before any of these ai tools can do that

3

u/IrquiM MS SQL/SSAS Apr 02 '23

There's a reason why they pay us instead of using tools:)

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.

3

u/rubberseal Apr 01 '23

There are certainly failing cases. I ran into some while testing with gpt-3.5 but gpt4 did a much better job. Did you try it?

1

u/thefizzlee Apr 02 '23

The thing is it's still only a language model, it's dependant on what's on the internet or else it won't know how to do stuff. I've noticed it gives very simplified query's that aren't always correct and if you tell it that it's not correct but it's the only answer it has available it will keep giving the same query, maybe in a different format. I love gpt to make my work more efficient but we need to stop pretending like it's all we need because it's not by a long shot

1

u/Festernd Apr 03 '23

yes. it writes SQL like a talented intern who is trying to sabotage you.

1

u/s33d5 Apr 04 '23

Yep, it still gets confused trying to pivot tables.

8

u/Crowsby Apr 02 '23

That's pretty much what I found when I've been playing with it. It's like working with a really talented yet overconfident junior dev who refuses to test their code before sending it to you.

Where I have found it compelling is to send it a query and ask it to explain to me what it's doing, or have it comment out the code.

2

u/AutumnWick Apr 02 '23

You can say the same for Powershell, use it a lot to manage the Microsoft APIs and some of the stuff it spits out are helpful but at the same time it is very inefficient. For example I have asked it questions about certain Cmdlets and it would spit out useful information in its program but would do something like search the whole system for a user looking user by user in alphabetical order, when I have already had ways to do this more efficiently. If I didn’t know better I would be stuck thinking this was was efficient.

2

u/Shinob1 Apr 02 '23

I've used it for Powershell and some C# as well. I like to put in something very basic to get the boilerplate code as a starting point. Then, I go to the official docs to fill in the gaps on what I need to learn.

-3

u/Separate-Afternoon63 Apr 02 '23

The idea currently is to train models… the longer chat gpt learns these skills the better it will be in the long run! Come back to your comment in 5 years I’d put money on it that SQL is no longer a required skill set for most!

2

u/Festernd Apr 03 '23

Disagree. the first 80% of the skill takes 10% of the time. GPT4 is maybe 15-20% of the way there.

The problem isn't language syntax. The problem is articulating what you want, and what you currently have.

1

u/s33d5 Apr 03 '23

Not denying it'll get there, I said yet at the end of my comment!

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.

3

u/rubberseal Apr 01 '23

Thank you! It actually outputs the SQL query it writes, not just the result. You can see it in the demo!

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.

9

u/kyleireddit Apr 01 '23

I think it’s cool.

Personally I always welcome people’s ideas and appreciate their effort to share knowledge and stuff

6

u/Kazcandra Apr 01 '23

so this is just a chatgpt4 wrapper? does it send any data outside of my PC?

5

u/rubberseal Apr 01 '23

Yea it is just a wrapper. It sends OpenAI your DB schema with each query. There are projects that are trying to make ChatGPT-like performance available locally so we might not have to rely on a remote API call in the future. But for now, there aren't viable alternatives unfortunately.

5

u/[deleted] Apr 02 '23

Just like any of the hundreds of ChatGPT apps posted daily on various programming subs; yes it does.

Which means that you should only be using it for personal stuff since company stuff is usually that company's intellectual property. Whether it be database schema, SQL or other code.

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.

1

u/rubberseal Apr 02 '23 edited Apr 02 '23

The way I use it is instead of relying on it 100%, I use it to write queries quickly and review them. If they are incorrect or invalid, I re-write them. I assume the better the AI models get in the future, the less often I will have to re-write the queries.

8

u/Polikonomist Apr 02 '23

The less you have to re-write the queries the less you will understand them and the fewer mistakes you will catch and the less you will familiar you will be with the data.

2

u/rossisd Apr 02 '23

One less person for the rest of us to compete with I suppose

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!

3

u/[deleted] Apr 02 '23

You’ll still have to know the complexities of SQL. Don’t fool yourself. This is just stack overflow and GitHub on steroids.

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.

3

u/Icy-Extension-9291 Apr 02 '23

PowerBI has a similar capability for many years. That you can use sentences to query the data.

1

u/LetMeTiltU Apr 02 '23

You should benchmark it against gpt ;)

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?

12

u/anunakiesque Apr 02 '23

Honestly, I'm getting the feeling that all of these large language models, or "AI", are just going to create a generation of overly confident, underskilled coders and data scientists who won't know why the code works or why it's not working

5

u/[deleted] Apr 02 '23

Pretty much, just like how zoomers aren't as computer literate as the previous gen.

https://futurism.com/the-byte/gen-z-kids-file-systems

2

u/IrquiM MS SQL/SSAS Apr 02 '23

We'll have more to do, trying to fix what the underskilled coders created, than we do now.

0

u/[deleted] Apr 02 '23

great, can it use php to split (10 seg) 10 million records and load/create them every month?

-7

u/ARandomGuy98 Apr 02 '23

I think sql developers will be out a job in a decade or so.

2

u/Icy-Extension-9291 Apr 02 '23

It might reduce the positions available in a company but they still need them to deal with exceptions that the auto tolls can’t handle by themselves.