Skip to main content

CALL prompt_explain

Explain a query

You can ask MotherDuck AI to explain a query using the prompt_explain table function.

Syntax

CALL prompt_explain('<SQL query>', [include_tables=['<table_name>', '<table_name>']);

Example usage

We use MotherDuck's sample Hacker News dataset from MotherDuck's sample data database.

CALL prompt_explain('
SELECT COUNT(*) as domain_count,
SUBSTRING(SPLIT_PART(url, ''//'', 2), 1, POSITION(''/'' IN SPLIT_PART(url, ''//'', 2)) - 1) as domain
FROM hn.hacker_news
WHERE url IS NOT NULL GROUP BY domain ORDER BY domain_count DESC LIMIT 10;
');

Output of this SQL statement is a single column table with the following content:

explanation
The query is running against a table called hacker_news under the schema hn. This table has a column named url. The purpose of the query is to find the top 10 most frequently mentioned domains in the URLs present in the hacker_news table.

Notes

MotherDuck AI operates on your current database by evaluating the schemas and contents of the database. You can specify which tables and columns should be considered, using the optional include_tables parameter. By default, all tables in the current database are considered. To point MotherDuck AI at a specific database, execute the use database command (learn more about switching databases).

These capabilities are provided by MotherDuck's integration with OpenAI.