diff --git a/src/content/docs/d1/build-with-d1/import-export-data.mdx b/src/content/docs/d1/build-with-d1/import-export-data.mdx index 11cac872181102..af924164e6184d 100644 --- a/src/content/docs/d1/build-with-d1/import-export-data.mdx +++ b/src/content/docs/d1/build-with-d1/import-export-data.mdx @@ -167,32 +167,37 @@ If you receive an error when trying to import an existing schema and/or dataset ### 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: +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. -- Convert a single large `INSERT` statement into multiple smaller `INSERT` statements. For example: +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. + +Before: ```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'), + ('1', 'Jacquelin Elara', '2022-08-20 05:39:52'), + ('2', 'Hubert Simmons', '2022-12-15 21:56:13'), ... - ('01GREFXCNF67KV7FPPSEJVJMEW', 'Riane Zamora', '2022-12-24 06:49:04'); + ('1000', 'Boris Pewter', '2022-12-24 07:59:54'); ``` -- Break it into multiple `INSERT` statements: +After: ```sql INSERT INTO users (id, full_name, created_on) VALUES -('01GREFXCN9519NRVXWTPG0V0BF', 'Catlaina Harbar', '2022-08-20 05:39:52'); + ('1', 'Jacquelin Elara', '2022-08-20 05:39:52'), + ... + ('100', 'Eddy Orelo', '2022-12-15 22:16:15'); +... INSERT INTO users (id, full_name, created_on) VALUES -('01GREFXCNBYBGX2GC6ZGY9FMP4', 'Hube Bilverstone', '2022-12-15 21:56:13'); + ('901', 'Roran Eroi', '2022-08-20 05:39:52'), + ... + ('1000', 'Boris Pewter', '2022-12-15 22:16:15'); ``` -- 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.