execute_sql_file
Execute SQL files for database migrations, schema changes, or data imports. Supports atomic transactions, validation preview, and pattern stripping for compatibility.
Instructions
Execute a .sql file from the filesystem. Useful for running migration scripts, schema changes, or data imports. Supports transaction mode for atomic execution. Max file size: 50MB. Use validateOnly=true to preview without executing. Use stripPatterns to remove delimiters like '/' (Liquibase) or 'GO' (SQL Server). Optionally use server/database/schema params for one-time execution on a different server.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filePath | Yes | Absolute or relative path to the .sql file to execute | |
| useTransaction | No | Wrap execution in a transaction (default: true). If any statement fails, all changes are rolled back. | |
| stopOnError | No | Stop execution on first error (default: true). If false, continues with remaining statements. | |
| stripPatterns | No | Patterns to strip from SQL before execution. E.g., ['/'] for Liquibase, ['GO'] for SQL Server. By default, patterns are matched as literal strings on their own line. | |
| stripAsRegex | No | If true, stripPatterns are treated as regex patterns (default: false). Use for complex patterns like '^\\s*/\\s*$'. | |
| validateOnly | No | If true, parse and preview the file without executing (default: false). Returns statement count and types. | |
| server | No | One-time server override. Execute on this server without changing main connection. | |
| database | No | One-time database override. Uses this database for execution. | |
| schema | No | One-time schema override. Sets search_path for this execution only. |