The recent boom in artificial intelligence technology has prompted many professionals in even high-skill roles to think about what the future of their careers will look like. One of the popular newer applications of artificial intelligence is for generating SQL queries. For many years, SQL has been an important technology for risk and fraud analysts, data analysts, business operations teams, and engineers alike to analyze and action upon company data. In the past, it’s mostly been a skill that a human being needed to learn and practice in order to wield.
Enter artificial intelligence. OpenAI’s release of their new ChatGPT program comes with a module to autogenerate SQL queries. The program can help you write, debug, and edit SQL queries. Let’s take a look at what it’s capable of.
AI can be used to automatically generate SQL queries. You can simply describe in natural language what type of data you’d like it to query and it can generate a logically correct SQL block for you. You can also specify what your data schema looks like so it can generate a SQL query that matches your database schema. If a schema is not specified, it will generate a query based on its prediction of what a typical schema would look like for your prompt.
AI can also go beyond just writing SQL queries to help you debug your SQL queries. You can give it an existing SQL query and ask it to fix any issues. In this example, we instructed AI to help us fix a count syntax error.
The AI dutifully fixed the query and returned a functioning result.
Finally, AI can even help you edit SQL queries. In this example we’ve asked AI to modify a SQL block that queries for users with greater than 10 logins to users who’ve logged in more than 2X the average number of logins per user.
AI can go beyond just generating the SQL queries, but it can also explain why it generated them and how the queries work to aid a human analysts’ learnings. Here’s the explanation generated for the query above.
Pretty neat! So if an AI can help you write, debug, and edit SQL queries, can it replace a full human analyst? Well, let’s not get out over our skis. Let’s take a look at the things AI can’t do.
While AI can generate SQL queries by mapping the query to specific database columns and tables that make the most logical sense, in the real world, many companies have data schemas that are very entangled, complicated and difficult to reason about without having the full context behind what each field or table means.
For example, you can instruct AI to help you write a query to calculate month over month revenue growth, but if the way your company calculates revenue is very complex and involves ambiguous decision making, an AI will struggle with the solution. Reasons why such a query to track revenue could be difficult to calculate:
These complex decisions don’t always have a straightforward answer and involve human understanding and decision making to produce solutions. AI does not understand the company specific meaning and business logic behind each field or table it’s asked to query.
AI technology is still new and therefore not 100% accurate. It’s still very much advised that a human who understands data review queries generated by AI before executing them in production. It’s possible that the AI doesn’t have enough context to generate the correct SQL query or is trying to apply a different, incorrect context to yours. Therefore, a human analyst would need to review and refine the query to ensure it is accurate and meaningful.
AI also may not be able to generate very complex SQL queries. Particularly, queries that require a deep understanding of the data schema or business logic. These queries may require window functions, multiple levels of subqueries, or even advanced statistical or machine learning techniques. AI development is not currently at a stage where it can handle all levels of complexity.
Finally, while AI may be able to identify patterns and correlations in data in order to generate a SQL query, a human analyst would ultimately need to interpret those findings and make recommendations based on their expertise and domain knowledge. Being able to generate the SQL query is only a part of the job. Being able to interpret what the results mean and determining how to act upon those results using a tool like LogicLoop is still very much a responsibility that a human needs to take on.
All these considerations mentioned above are very important components of a SQL analyst's job at a company. A SQL analyst would not be a very effective one if they couldn’t interpret business logic and act upon results.
Ultimately, we don’t think AI can fully replace a SQL analyst. Instead, we think AI can enhance a SQL analyst's job by allowing them to perform more quickly and efficiently. Don’t believe us? Believe the AI:
LogicLoop is exploring helping analysts become more productive and effective with AI assisted SQL generation. Check here to sign up for our AI SQL Beta.