diff --git a/typescript-client/sqlUtils.ts b/typescript-client/sqlUtils.ts index 4c1ccd7ea4..f29ff4e423 100644 --- a/typescript-client/sqlUtils.ts +++ b/typescript-client/sqlUtils.ts @@ -256,8 +256,12 @@ function buildSqlStatement( // silently became NULL in the database. The // executor accepts these literals via // `Value::String → FLOAT8` (`f64::from_str`). +// - array → each element serialized as above. `TYPE[]` +// slots parse string elements the same way; a +// JSON-typed array stores them as strings. // - everything else → passed through unchanged. function serializeArgValue(v: any): any { + if (Array.isArray(v)) return v.map(serializeArgValue); if (typeof v === "bigint") return v.toString(); if (v instanceof Date) return v.toISOString(); if (typeof v === "number" && !Number.isFinite(v)) { diff --git a/typescript-client/tests/sqlUtils.test.ts b/typescript-client/tests/sqlUtils.test.ts index 32fcda259f..07d8a26986 100644 --- a/typescript-client/tests/sqlUtils.test.ts +++ b/typescript-client/tests/sqlUtils.test.ts @@ -139,6 +139,7 @@ function parseTypeAnnotation( } function serializeArgValue(v: any): any { + if (Array.isArray(v)) return v.map(serializeArgValue); if (typeof v === "bigint") return v.toString(); if (v instanceof Date) return v.toISOString(); if (typeof v === "number" && !Number.isFinite(v)) { @@ -455,6 +456,19 @@ describe("datatable() — template tag", () => { expect(sql`SELECT ${NaN}`.content).toContain("$1::DOUBLE PRECISION"); }); + test("BigInt and non-finite array elements are stringified", () => { + const sql = dt(); + const out = sql`SELECT ${[1n, 2n]}`; + expect(out.content).toContain("$1::BIGINT[]"); + expect(out.args.arg1).toEqual(["1", "2"]); + expect(() => JSON.stringify(out.args)).not.toThrow(); + expect(sql`SELECT ${[1.5, NaN, -Infinity]}`.args.arg1).toEqual([ + 1.5, + "NaN", + "-Infinity", + ]); + }); + test("homogeneous arrays auto-tag with TYPE[]", () => { const sql = dt(); expect(sql`SELECT ${[1, 2, 3]}`.content).toContain("$1::BIGINT[]");