Overview
Execute a SQL query on the DuckDB or MotherDuck database. Unqualified table names resolve tocurrent_database() and current_schema() automatically. Fully qualified names (database.schema.table) are only needed when multiple DuckDB databases are attached or when connected to MotherDuck.
Parameters
SQL query to execute using DuckDB SQL dialect. Supports all DuckDB SQL operations including SELECT, INSERT, UPDATE, DELETE, CREATE TABLE, aggregations, window functions, and analytical queries.
Response
Indicates whether the query executed successfully.
Array of column names returned by the query. Empty for non-SELECT statements.
Array of column data types corresponding to the columns. DuckDB type names (e.g., “VARCHAR”, “BIGINT”, “DOUBLE”, “DATE”, “TIMESTAMP”).
Array of rows, where each row is an array of values. Maximum of 1024 rows returned by default (configurable with —max-rows).
Number of rows returned in the response.
Present when results exceed the maximum row or character limits. Indicates that not all data was returned.
Warning message when results are truncated, explaining the limit that was reached.
Error message when success is false. Contains detailed error information.
Type of error that occurred (e.g., “CatalogException”, “ParserException”, “BinderException”).
Examples
SELECT Query
Aggregation Query
INSERT Query
CREATE TABLE Query
Truncated Results
Error Response
Tool Annotations
Read-Only Mode: When the server is started with
--read-only, this tool has readOnlyHint: true and destructiveHint: false. In read-write mode (default), it has readOnlyHint: false and destructiveHint: true.Error Handling
The tool returns structured error responses when queries fail:- CatalogException: Table or column does not exist
- ParserException: SQL syntax error
- BinderException: Invalid column reference or type mismatch
- ConstraintException: Constraint violation (PRIMARY KEY, NOT NULL, etc.)
- IOException: File access or S3 connection issues
- TimeoutException: Query exceeded the configured timeout
Best Practices
- Use LIMIT clauses: For exploratory queries on large tables, always use LIMIT to avoid overwhelming results
- Qualify table names: When working with multiple databases, use fully qualified names:
database.schema.table - Handle truncation: Check for the
truncatedfield and adjust queries or increase limits if needed - Error handling: Always check the
successfield before processing results - Read-only mode: Be aware of server mode - write operations will fail in read-only mode