SQL assistant
Built-in SQL functions that use AI to help you work with SQL. Generate SQL queries, execute read-only questions directly, fix errors, explain queries, and more.
These functions can be useful building blocks for AI-driven analytics solutions or used stand-alone on all MotherDuck surfaces (including the CLI).
To use external tools like Claude Desktop or Cursor with MotherDuck, see the MCP Server setup guide (or the local MCP server for self-hosted, read-write use).
Available functions
PROMPT_QUERY
Answer natural language questions about your data using the PROMPT_QUERY function.
PROMPT_SQL
Generate SQL queries from natural language descriptions using the PROMPT_SQL function.
PROMPT_EXPLAIN
Get AI-generated explanations of SQL queries using the PROMPT_EXPLAIN function.
PROMPT_FIX_LINE
Fix SQL query errors line by line using the PROMPT_FIX_LINE function.
PROMPT_FIXUP
Automatically fix SQL query errors using the PROMPT_FIXUP function.
PROMPT_SCHEMA
Describe database contents using the PROMPT_SCHEMA function for AI-generated schema summaries.
Notes
SQL assistant functions operate 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 the SQL assistant functions at a specific database, execute the USE database command (learn more about switching databases).
These capabilities are provided by MotherDuck's integration with Azure OpenAI.
For availability and pricing, see MotherDuck's Pricing Model.
If you have further questions or specific requirements, please see our support page.
Regional processing
Requests are processed based on your MotherDuck organization's region. The table below shows the processing regions where each function is available. An organization whose own region has no in-region AI processing is routed to another region, as listed below the table.
| Function | Global | Europe | US West |
|---|---|---|---|
| SQL Assistant Functions | ✓ | ✓ | ✓ |
Organizations in regions without in-region AI processing are routed as follows:
- Europe (Dublin)
eu-west-1is served by the European processing region (the Europe column above), the same as Europe (Frankfurt)eu-central-1. - Asia Pacific (Sydney)
ap-southeast-2and Asia Pacific (Tokyo)ap-northeast-1are served by a US-based endpoint.
In these regions, the SQL, schema, and sampled table data the SQL assistant functions evaluate (including anything embedded in your SQL, such as comments) leaves your organization's AWS region for processing: within Europe for Dublin, and in the United States for the Asia Pacific regions. If your data residency requirements do not allow this, contact support before using the SQL assistant functions in that region.
Data usage
The data processed by MotherDuck's AI functionality is not used for model training.