Skip to content
← Back to activity

Immutable solution version

Server returned HTTP status 400: SQL text 0 not found

Version 1Sign in to save

Complete solution

How to fix 'Server returned HTTP status 400: SQL text 0 not found' in Turso, straight from the verified resolution in gh:tursodatabase/libsql-client-ts#177. Root cause plus what to change.

What was reported

Issue tursodatabase/libsql-client-ts#177 (closed, 5 comments): Hello! I get the following error Server returned HTTP status 400: SQL text 0 not found. This happens when batch inserting 50 rows, if I shrink this array everything works fine.

sqld sqld 0.22.14 (2931e2b5 2024-01-18)
"@libsql/client": "^0.4.3",
import { createClient } from "@libsql/client"
export const sqlite = createClient({ url: dbUrl })

Failed (batch, 50 rows):

    sqlite.batch([`
    INSERT INTO asset (fingerprint, policy_id, asset_name, ref_fingerprint, quantity)
        VALUES
          ('asset100kvrdjjqk4dasq8l8mjv6kmm9gvphv6wq3d32','b863bc73

## The verified resolution

[invisal (commenter), root cause found via Discord discussion]: The client's batch() stores statements server-side via `stored_sql`, which Turso/sqld limits to ~5KB  -  so larger batches fail with `Server returned HTTP status 400: SQL text 0 not found`. The client had no way to opt out of stored_sql for batches. Workaround at the time: libsql-stateless-easy (stateless batching). (No maintainer fix stated in the thread.)

Evidence

Asked in gh:tursodatabase/libsql-client-ts#177 (https://github.com/tursodatabase/libsql-client-ts/issues/177): Server returned HTTP status 400: SQL text 0 not found. The issue report: Issue tursodatabase/libsql-client-ts#177 (closed, 5 comments): Hello! I get the following error Server returned HTTP status 400: SQL text 0 not found. This happens when batch inserting 50 rows, if I shrink this array everything works fine.

sqld sqld 0.22.14 (2931e2b5 2024-01-18)
"@libsql/client": "^0.4.3",
import { createClient } from "@libsql/client"
export const sqlite = createClient({ url: dbUrl })

Failed (batch, 50 rows):

    sqlite.batch([`
    INSERT INTO asset (fingerprint, policy_id, asset_name, ref_fingerprint, quantity)
        VALUES
          ('asset100kvrdjjqk4dasq8l8mjv6kmm9gvphv6wq3d32','b863bc73 The verified answer: [invisal (commenter), root cause found via Discord discussion]: The client's batch() stores statements server-side via `stored_sql`, which Turso/sqld limits to ~5KB  -  so larger batches fail with `Server returned HTTP status 400: SQL text 0 not found`. The client had no way to opt out of stored_sql for batches. Workaround at the time: libsql-stateless-easy (stateless batching). (No maintainer fix stated in the thread.)

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_dSlgBNVkgUHIvTcHa0qujA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Server returned HTTP status 400: SQL text 0 not found <span>— Vectle</span></a>