Skip to content

Commit

Permalink
[D1] Adding info on resolving 'statement too long' errors while impor…
Browse files Browse the repository at this point in the history
…ting. (#17373)

* Resolving 'statement too long' errors while importing.

* Apply suggestions from code review

Co-authored-by: Pedro Sousa <680496+pedrosousa@users.noreply.github.com>

* Changing into unordered bullet point.

* Using unordered bullet points.

---------

Co-authored-by: Pedro Sousa <680496+pedrosousa@users.noreply.github.com>
  • Loading branch information
Oxyjun and pedrosousa authored Oct 8, 2024
1 parent 2f81e5f commit 86226ff
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/content/docs/d1/build-with-d1/import-export-data.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,34 @@ If you receive an error when trying to import an existing schema and/or dataset
- If you have foreign key relationships between tables, ensure you are importing the tables in the right order. You cannot refer to a table that does not yet exist.
- If you receive a `"cannot start a transaction within a transaction"` error, make sure you have removed `BEGIN TRANSACTION` and `COMMIT` from your dumped SQL statements.

### Resolve `Statement too long` error

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:

- Convert a single large `INSERT` statement into multiple smaller `INSERT` statements. For example:

```sql
INSERT INTO users (id, full_name, created_on)
VALUES
('01GREFXCN9519NRVXWTPG0V0BF', 'Catlaina Harbar', '2022-08-20 05:39:52'),
('01GREFXCNBYBGX2GC6ZGY9FMP4', 'Hube Bilverstone', '2022-12-15 21:56:13'),
...
('01GREFXCNF67KV7FPPSEJVJMEW', 'Riane Zamora', '2022-12-24 06:49:04');
```

- Break it into multiple `INSERT` statements:

```sql
INSERT INTO users (id, full_name, created_on)
VALUES
('01GREFXCN9519NRVXWTPG0V0BF', 'Catlaina Harbar', '2022-08-20 05:39:52');
INSERT INTO users (id, full_name, created_on)
VALUES
('01GREFXCNBYBGX2GC6ZGY9FMP4', 'Hube Bilverstone', '2022-12-15 21:56:13');
```

- 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.

## Next Steps

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

0 comments on commit 86226ff

Please sign in to comment.