Skip to main content

Write SQL with AI

Access SQL Assistant functions

MotherDuck provides built-in AI features to help you write, understand and fix DuckDB SQL queries more efficiently. These features include:

Example usage of prompt_sql

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

CALL prompt_sql('what are the top domains being shared on hacker_news?');

Output of this SQL statement is a single column table that contains the AI-generated SQL query.

query
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

Automatically Fix SQL Errors in the WebUI

FixIt is a MotherDuck AI-powered UI feature that helps you resolve common SQL errors by offering fixes in-line. Read more about it in our blog post. FixIt can also be called programmatically using the prompt_fix_line . Find more information here.

How FixIt works

By default, FixIt is enabled for all users. If you run a query that has an error, FixIt will automatically analyze the query and suggest in-line fixes.

FixIt

FixIt

You can choose to accept, to reject, or to ignore a fix. If you accept a fix, MotherDuck will automatically update your query and re-execute it.

You can also generate a different suggestion if the proposed fix is inaccurate.

How to disable FixIt

You can disable FixIt by clicking on the FixIt icon in the top right corner of the query editor.