Live data from Hacker News

How to generate SQL statements with ChatGPT

forta.com

31–40 of 48 posts

Re: How to generate SQL statements with ChatGPT

#31
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.

It's really good at generating sqlite db's[0] too.

0 - https://chat.openai.com/share/5534e0b2-4010-4da6-99b9-a3aa02...

Re: How to generate SQL statements with ChatGPT

#32
post #7

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? I had to forbid my coworkers from using chatgpt to generate SQL because it kept doing things slightly wrong - like missing parens when dealing with AND and OR in a where statement.

> 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.

Re: How to generate SQL statements with ChatGPT

#33

Earlier quoted context omitted.

Most people can read more complicated text than they can write. Most people who need to generate a query can run it and look at the results. I use chatgpt to help me, particularly with languages I don’t write in everyday. And I often find myself arguing with chatgpt that what it wrote is wrong, because I can read the query, but don’t know how to write the query I need.

I agree with your sentiment but it actually occurred to me that code might actually be the reverse - where you can write more complicated code than you can read.

A nice corollary to Kernighan's law on debugging.

I guess it can go either way. Sometimes ChatGPT4 is great and saves me time, but the cycle of "explain what I want, get the output test/compile it, post the errors, try again" doesn't always converge quickly enough to not be more irritating than actually learning the issues in the code I'm trying to interface with. So I'll try it a bit, but if it goes back and forth more than 3 or 4 times, I'll give up and dig in to study the thing.

Re: How to generate SQL statements with ChatGPT

#34
Anyone can do something like this now by searching Google or asking Clippy. The act of double-checking what the interface suggests is the same as doing the thinking and work manually. Perhaps more intelligent error messages would be helpful, or performance improvement suggestions.

Re: How to generate SQL statements with ChatGPT

#35
post #17

I've spent a lot of time on this problem space for our business. My current conclusions are as follows: Writing the actual SQL query is not the hard part for us. The hardest part is exhaustively expressing our intention in any language at all , followed closely by its apprentice - the incomplete requirements monster. I've found that if I can coach a team member into giving me a proper natural language statement that…

Subqueries and windowing and partitioning are annoying tedious areas if you only use that sort of SQL occasionally (<1/month) and the GPT4 API seems to massively help for turning plain text into the appropriate stuff. I know enough to be able to be confident in it after running some tests of the query, but not enough to knock it out cold without a few minutes research.

Re: How to generate SQL statements with ChatGPT

#36
post #17

I've spent a lot of time on this problem space for our business. My current conclusions are as follows: Writing the actual SQL query is not the hard part for us. The hardest part is exhaustively expressing our intention in any language at all , followed closely by its apprentice - the incomplete requirements monster. I've found that if I can coach a team member into giving me a proper natural language statement that…

>>* ...Anything serious...* My problem is that I simply cannot trust any data coming from GPT - it doesnt have real-time info, it constantly tells me what it CANT DO and its never able to tell me what it CAN DO. The platform is extremely powerful, and what we are seeing is that the cadre of AI LLMs/apps that are coming about has all the devs/companies frantically running in a panic on how to both weaponize and moneti…

>"My problem is that I simply cannot trust any data coming from GPT"

I just used it to write shell function which extracts value from .ini file using section, name as a parameters. Works perfectly. Otherwise I would have to manually dick with awk input string wrecking my brain in the process

Re: How to generate SQL statements with ChatGPT

#37
post #36

Earlier quoted context omitted.

>>* ...Anything serious...* My problem is that I simply cannot trust any data coming from GPT - it doesnt have real-time info, it constantly tells me what it CANT DO and its never able to tell me what it CAN DO. The platform is extremely powerful, and what we are seeing is that the cadre of AI LLMs/apps that are coming about has all the devs/companies frantically running in a panic on how to both weaponize and moneti…

>"My problem is that I simply cannot trust any data coming from GPT" I just used it to write shell function which extracts value from .ini file using section, name as a parameters. Works perfectly. Otherwise I would have to manually dick with awk input string wrecking my brain in the process

function validation is not same as information validation and links to information from [world]\\

I would EXPECT/DEMAND your results - other results are not functions.

Re: How to generate SQL statements with ChatGPT

#38
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

Re: How to generate SQL statements with ChatGPT

#40
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.

> 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.

Post reply on HN