#4948 🐛 BUG: D1 local execute fails with ALTER TABLE
Cannot reproduce with wrangler 4.60.0 - ALTER TABLE via --local --file works correctly
Close with comment explaining fix
Analysis Report
Issue Review: cloudflare/workers-sdk#4948
Summary
D1 wrangler d1 execute --local --file fails with "A prepared SQL statement must contain only one statement" error when executing ALTER TABLE statements, while remote execution works fine.
Findings
- Created: 2024-02-07
- Updated: 2025-10-30
- Version: 3.27.0 → 4.60.0 (current)
- Component: D1 (wrangler)
- Labels: bug, d1
- Comments: 0
Key Evidence
Reproduction Attempt (wrangler 4.60.0): CANNOT REPRODUCE
- Created table with DDL file successfully:
npx wrangler d1 execute test_db --local --file=./my_ddl.sql✓ - Executed ALTER TABLE via file successfully:
npx wrangler d1 execute test_db --local --file=./update.sql✓ - Verified column was added via PRAGMA table_info ✓
- Created table with DDL file successfully:
Related Changes Since Issue Creation:
- PR #4951 (2024-02-09): Fixed batch splitting to handle CASE as compound statement starts
- PR #5696 (2024-05-16): D1 execute --file --remote now uses dedicated import API (explains why remote worked)
- PR #4930 (2024-03-11): Default d1 execute to local mode first
- Major version upgrade: wrangler 3.x → 4.x with significant D1 improvements
Issue Number Not Found: No explicit "Fixes #4948" PR found, but the fix was likely part of cumulative improvements to SQL statement parsing/batch handling.
Recommendation
Status: CLOSE
Reasoning: The issue cannot be reproduced with wrangler 4.60.0. The ALTER TABLE statement that was failing in version 3.27.0 now executes successfully with --local --file. This was likely fixed as part of the numerous D1 improvements merged since February 2024, including fixes to statement batch splitting and the transition to wrangler v4.
Action: Close the issue with a comment explaining the fix and suggesting reporter verify with current wrangler version if still experiencing issues.
Suggested Comment
This issue appears to have been fixed in the current version of wrangler (4.60.0). I was able to successfully reproduce the exact scenario described:
- Created a table using
wrangler d1 execute --local --file=./my_ddl.sql- Executed
ALTER TABLE tbl ADD COLUMN example TEXT;viawrangler d1 execute --local --file=./update.sqlBoth commands completed successfully without the "A prepared SQL statement must contain only one statement" error.
This was likely fixed as part of the cumulative D1 improvements since February 2024, including PR #4951 which improved statement batch splitting.
If you're still experiencing this issue, please upgrade to the latest wrangler version (
npm install wrangler@latest) and let us know if the problem persists. Closing this as resolved.