Skip to content

Commit 31dac86

Browse files
authored
[D1] Statement too long fix (#17393)
* Clarifying ambiguous wording. * Enhancing example for resolving long INSERT statements. * Removing redundant line.
1 parent aea752d commit 31dac86

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/content/docs/d1/build-with-d1/import-export-data.mdx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -167,32 +167,37 @@ If you receive an error when trying to import an existing schema and/or dataset
167167

168168
### Resolve `Statement too long` error
169169

170-
If you encounter a `Statement too long` error when trying to import a large SQL file into D1, it means that one of the SQL statements in your file exceeds the maximum allowed length. To resolve this issue, try one of the following approaches:
170+
If you encounter a `Statement too long` error when trying to import a large SQL file into D1, it means that one of the SQL statements in your file exceeds the maximum allowed length.
171171

172-
- Convert a single large `INSERT` statement into multiple smaller `INSERT` statements. For example:
172+
To resolve this issue, convert the single large `INSERT` statement into multiple smaller `INSERT` statements. For example, instead of inserting 1,000 rows in one statement, split it into four groups of 250 rows, as illustrated in the code below.
173+
174+
Before:
173175

174176
```sql
175177
INSERT INTO users (id, full_name, created_on)
176178
VALUES
177-
('01GREFXCN9519NRVXWTPG0V0BF', 'Catlaina Harbar', '2022-08-20 05:39:52'),
178-
('01GREFXCNBYBGX2GC6ZGY9FMP4', 'Hube Bilverstone', '2022-12-15 21:56:13'),
179+
('1', 'Jacquelin Elara', '2022-08-20 05:39:52'),
180+
('2', 'Hubert Simmons', '2022-12-15 21:56:13'),
179181
...
180-
('01GREFXCNF67KV7FPPSEJVJMEW', 'Riane Zamora', '2022-12-24 06:49:04');
182+
('1000', 'Boris Pewter', '2022-12-24 07:59:54');
181183
```
182184

183-
- Break it into multiple `INSERT` statements:
185+
After:
184186

185187
```sql
186188
INSERT INTO users (id, full_name, created_on)
187189
VALUES
188-
('01GREFXCN9519NRVXWTPG0V0BF', 'Catlaina Harbar', '2022-08-20 05:39:52');
190+
('1', 'Jacquelin Elara', '2022-08-20 05:39:52'),
191+
...
192+
('100', 'Eddy Orelo', '2022-12-15 22:16:15');
193+
...
189194
INSERT INTO users (id, full_name, created_on)
190195
VALUES
191-
('01GREFXCNBYBGX2GC6ZGY9FMP4', 'Hube Bilverstone', '2022-12-15 21:56:13');
196+
('901', 'Roran Eroi', '2022-08-20 05:39:52'),
197+
...
198+
('1000', 'Boris Pewter', '2022-12-15 22:16:15');
192199
```
193200

194-
- If you have a single large `INSERT` statement with many rows, break it into smaller chunks. For example, instead of inserting 1,000 rows in one statement, try splitting that into 250 rows.
195-
196201
## Next Steps
197202

198203
- Read the SQLite [`CREATE TABLE`](https://www.sqlite.org/lang_createtable.html) documentation.

0 commit comments

Comments
 (0)