Writing SQL queries with ChatGPT

SQL is, funny enough, one of the primary reasons that I ended up in product management. I taught myself to write SQL while I was doing my MBA, and then actually learned it as an intern at WorldRemit when I had a real world (and partially Spanish) database that I could ask questions of. It helped me to solve some real business problems, and I found myself with my first full-time job in product as a result.

SQL has also taught me a few things about how to think and how to work. I often found that a query that was intractable at 3pm would seem simple at 9am the next morning. Learning about ERD diagrams deeply influenced (I’m only realizing as I write this) the way that I understand technology and approach building products (very architecturally). It also, frankly, was a point of pride to have a skill that many of my product compatriots did not.

So thank you SQL.

In the last few years I haven’t had much opportunity to write SQL, but I’ve had reason to come back to it in the last few weeks. And while the basics are still there, anything beyond relatively basic queries has been difficult to carve out time to work through.

Enter ChatGPT.

I’m still at a point where it doesn’t occur to me straight away to use ChatGPT (or Gemini, or etc) for a problem like this, though at some point it does occur to me, which is new in the last couple months. I have found these tools close to unusable for anything related to writing: marketing copy, sales emails, my own personal writing - very bad. But for writing SQL - oh boy.

Writing SQL obviously requires an understanding of the database, so I chose to create a personal GPT for my SQLing purposes. I fed the GPT creator a few table names and columns, and nothing more than that. By adding a bit of additional context to my prompts (remove records where superwave_internal = ‘true’), my GPT cranks out queries in minutes that would have previously taken me hours. Wild.

It’s not perfect. I haven’t put all of the tables and column names into knowledge yet, and when I ask for a query that requires a table that my GPT doesn’t know, it makes assumptions instead of saying ‘I don’t know'. It also selectively stored the tables and column names that I gave it. But in general, it’s a lot faster than me + Stack Overflow.

The meta-question, of course, is ‘is this good'? I find I have very mixed feelings. I can get to answers much more quickly than I would otherwise, and spend my time (in theory) on higher value work. I can also intellectually appreciate that our entire economic system rests on improving productivity. But I find there is something slightly unnerving about a skill that I (clearly) have quite a personal connection to being completely commoditized.