Stories
Slash Boxes
Comments

SoylentNews is people

Submission Preview

Link to Story

Can ChatGPT Write Better SQL than a Data Analyst?

Accepted submission by guest reader at 2023-03-15 19:31:46 from the too-lazy-to-write-sql dept.
Science

Extracting information from databases requires skill and knowledge of query languages like SQL (Structured Query Language).
Natural language querying (NLQ) which is also called Text-to-SQL allows formation of information retrieval questions without knowledge of database-specific languages. ChatGPT is the next level in this area.

Data analyst Marie Truong challenged ChatGPT [towardsdatascience.com] to write better SQL in January. She is comparing valid SQL syntax, query structure, correct results, and runtime. The result? ChatGPT got 50% of it wrong.

One of many new articles [arxiv.org] about this topic tries to convert database schemas into natural language as part of chatgpt prompts to provide more precise outcomes:

There has been an expectation that ChatGPT could assist in creating database queries, just as it can assist in creating computer programs. However, creating database queries requires an understanding of the database itself, and there is no conventional way to represent database semantics.

We present a solution to this problem by developing a set of syntax that can represent database semantics, such as table structure and relationships, in natural language. This allows for the creation of semantic representations of databases that can be understood by ChatGPT and enable it to perform database management tasks.

Experiment 2:
A SQL query needs to properly join four tables: careplans, providers, patients, and encounters. The encounters table plays a critical role here as it connects the patients table with the careplans table. This information is typically contained in an Entity Relationship schema.

ChatGPT has successfully generated the query that results in a correct view.

There has been a research about generating SQL queries from natural language [mecs-press.org] since 2016.


Original Submission