Skip to content

.where('col', 'in', value) fails when value is a TypedArray (e.g. Int32Array) returned by Bun SQL (PostgreSQL integer[]) #411

@vortizhe

Description

@vortizhe

Hi — I'm hitting a bug where kysely-postgres-js fails to compile queries when the value passed to .where('col', 'in', value) is a TypedArray (Int32Array) instead of a plain JS Array.

What happens

Bun SQL returns PostgreSQL integer[] columns as Int32Array (typed array), not number[].
Kysely call like:

const somedata = await db.selectFrom('sometable').selectAll().executeTakeFirst();
const dataIds = somedata?.dataIds; // Int32Array from Bun SQL
await db.selectFrom('wadus').where('id', 'in', dataIds).selectAll().execute();

The PostgresQueryCompiler expects a plain JavaScript array to expand the IN clause (IN ($1, $2, ...)). When given an Int32Array the compiler produces malformed SQL / crashes (it doesn't iterate/serialize the typed array correctly).

Expected behavior

Kysely should accept any array-like or iterable of primitives for the 'in' operator, including TypedArrays (Int8Array, Uint8Array, Int32Array, etc.), and expand them correctly into positional parameters.
At minimum, detect TypedArray and convert with Array.from(value) before compilation.
Environment

bun 1.3.8 (Bun SQL returns Int32Array for integer[] columns)
Kysely + kysely-postgres-js (version unconfirmed)

Actual workaround

Manually convert typed arrays before passing to Kysely:

await db.selectFrom('wadus').where('id', 'in', Array.from(dataIds)).selectAll().execute();

Happy to provide a small repro if helpful. Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions