Live data from Hacker News

How to generate SQL statements with ChatGPT

forta.com

41–48 of 48 posts

Re: How to generate SQL statements with ChatGPT

#41
post #6

If you can export your data to SQLite first (my https://datasette.io/tools/db-to-sqlite tool can help with that) you can upload the SQLite database directly to ChatGPT Code Interpreter and have it run the queries for you, since sqlite3 is in the Python standard library If you do this, it will automatically retry with a new SQL query if it gets any error messages.

I listened to you on the latentspacepod the other day and tried this method myself.

  1. Used GPT-4 to build functions that pulled in sample datasets from my BigQuery.

  2. Used GPT-4 to insert them into a sqlite database.

  3. Upload the zip file into Code Interpreter.

  4. Now I'm in an environment to quickly self-iterate on GPT-4 generated SQL.
It felt incredibly powerful. Previously I was developing with the latency of 100Gb+ tables – now the sqlite db responds instantly, and I don't even need to write the code.

Re: How to generate SQL statements with ChatGPT

#42
post #32

Earlier quoted context omitted.

> If you know SQL why is this better than just writing SQL? If you don’t know SQL how do you know it’s correct? You test it. And what do you mean by “know SQL?” No one knows everything about SQL. Virtually everyone writing SQL is in between the two extreme cases you provide.

If you understand SQL enough to know if the query ChatGPT produced is valid - you probably could have written it yourself. I don’t see how prompting chatgpt and testing its results is faster or better than just writing SQL.

Imo it depends on what you're prompting. If you yourself do not fully understand what you want and/or which information you have to provide for the model to 'understand' enough context, prompts will not give good results.

I usually find ChatGPT very good for converting conceptual ideas to a concrete piece of 'boilerplate' to work off of. It can help you jump gaps in your proces, but in the end you still have to make the jumps yourself.

Re: How to generate SQL statements with ChatGPT

#43
post #20

> "What happened to the company?" > "It collapsed because nobody knew how to maintain the queries—they generated everything with ChatGPT."

Isn't it how it works right now with Excel? Pretty sure every company relies on a obscure spreadsheet that no one knows how to maintain

I wouldn't be surprised, but there's at least someone around who could unwind it if necessary.

There's a big difference between limited access to domain experts and no access (or so limited that the costs are exorbitant or the individual is overwhelmed with opportunities).

My time horizon for these sorts of failures is ~10-20 years out. By that point, the younger generations coming into the workforce will have been fully conditioned (or just discouraged) out of thinking and building skills, wholly reliant on AI. I look it as a "gradually, then all of a sudden" problem.

Re: How to generate SQL statements with ChatGPT

#44
post #32

Earlier quoted context omitted.

> If you know SQL why is this better than just writing SQL? If you don’t know SQL how do you know it’s correct? You test it. And what do you mean by “know SQL?” No one knows everything about SQL. Virtually everyone writing SQL is in between the two extreme cases you provide.

If you understand SQL enough to know if the query ChatGPT produced is valid - you probably could have written it yourself. I don’t see how prompting chatgpt and testing its results is faster or better than just writing SQL.

I can recognize much more faces than I can describe/draw. It is easier to read foreign language than to write it (active vs passive vocabulary).

It is the same with googling, looking for a solution on StackOverflow: understanding/judging whether the solution is good may be faster than constructing it yourself.

Re: How to generate SQL statements with ChatGPT

#45
post #32

Earlier quoted context omitted.

If you understand SQL enough to know if the query ChatGPT produced is valid - you probably could have written it yourself. I don’t see how prompting chatgpt and testing its results is faster or better than just writing SQL.

> If you understand SQL enough to know if the query ChatGPT produced is valid Like I said, you need to test it. Not read it. Test it.

[deleted]

Re: How to generate SQL statements with ChatGPT

#46

the difficulty at my job is the many tables have no documentation, the transform code is inaccessible, and they were created by different teams by people who arent here any more. by the time i figure out what to write in the prompt most of my work is done.

lol, a lot of time I just copy paste the CREATE syntax into chatgpt and ask for help with how things are connected, it understands it pretty damn well. At some point some startup is going to come up with a backend-in-a-box where you just describe the tables, rules and it will spit out all Graphql mutations and queries, react components, an auth layer, etc... ChatGPT out of the box can do all of that right now, but it…

Yup! Pretty much magic!

Re: How to generate SQL statements with ChatGPT

#48
post #32

Earlier quoted context omitted.

If you understand SQL enough to know if the query ChatGPT produced is valid - you probably could have written it yourself. I don’t see how prompting chatgpt and testing its results is faster or better than just writing SQL.

> If you understand SQL enough to know if the query ChatGPT produced is valid Like I said, you need to test it. Not read it. Test it.

[deleted]
Post reply on HN