It's official: the age of Artificial Intelligence (AI) has arrived! Until our new overlords decide to use us to power their machines, let's take the time to fully enjoy all the benefits they provide and the myriad of ways that they make our lives easier. Case in point, the AI-driven chatbot, ChatGPT, by OpenAI, has been lauded for its ability to produce tremendously spot-on answers to questions across a broad range of topics. And, although ChatGPT may not be making our jobs obsolete just yet, it has proven to be amazingly adept at working with data sets, much like a DBMS. In today's blog, we'll explore how ChatGPT could be utilized to supplement a professional database development and administration tool like Navicat.
Creating the Data Set
ChatGPT is able to model a formal dataset from a list of delimited values. All you need to do is tell it what to do using regular, conversational language. ChatGPT is also able to answer follow-up questions, admit its mistakes, challenge incorrect premises, and reject inappropriate requests. We can see an example on the OUseful.Info blog that created a table named "racerresults". Here are the instructions given to ChatGPT, along with a sampling of the input data:
Treat the following as a tab separated dataset. Using just the first, third and fourth columns, treat the data as if it were a relational SQL database table called "racerresults" with columns "Race", "Driver" and "Team", and the "Race" column as a primary key column. Display a SQL statement that could create the corresponding table and populate it with the data. Bahrain 20 Mar 2022 Charles Leclerc FERRARI 57 1:37:33.584 Saudi Arabia 27 Mar 2022 Max Verstappen RED BULL RACING RBPT 50 1:24:19.293 Australia 10 Apr 2022 Charles Leclerc FERRARI 58 1:27:46.548 Emilia Romagna 24 Apr 2022 Max Verstappen RED BULL RACING RBPT 63 1:32:07.986 Miami 08 May 2022 Max Verstappen RED BULL RACING RBPT 57 1:34:24.258 Spain 22 May 2022 Max Verstappen RED BULL RACING RBPT 66 1:37:20.475 Monaco 29 May 2022 Sergio Perez RED BULL RACING RBPT 64 1:56:30.265 erc...
From the above instructions and data, ChatGPT generated the following CREATE TABLE and INSERT statements:
With the data in place, we're ready to run queries against it.
Querying a Data Set with ChatGPT
In terms of query formulation, ChatGPT shares some similarities with Navicat, in that both allow you to construct queries with little knowledge of SQL. To do that, Navicat features the Query Builder tool. Here it is in macOS:
As for ChatGPT, it takes a question phrased in regular, conversational language, and produces the required SQL statement(s). For instance, given the following list of historical figures:
We can simply as ChatGPT how it would query for the oldest historical figure. Here is the resulting SQL statement and explanation offered by ChatGPT:
Fun with Data
ChatGPT can do a lot more than generate queries; it can also think creatively to assign emojis to each historical figure:
Final Thoughts on Supercharging Your Queries with Navicat and ChatGPT
While AI bots like ChatGPT are a long way from replacing traditional database tools, they do offer another tool to database practitioners who are looking for new and innovative ways of approaching data-related tasks. At the time of this writing, ChatGPT was at capacity and unable to accept new users, but once things die down a bit, I would urge you to give ChatGPT a try.