Problem with parsing int64 values?
imirosedi opened this issue ยท 8 comments
When I'm trying to insert BigInt and Timestamp values, I get errors, both with prepared statements and appenders. I'm not sure if it's a bug or me doing something wrong, because there are no mentions of BigInts and Timestamps in the documentations for now.
How to Reproduce the Problem
Here is a minimal test case:
import { DuckDBInstance, DuckDBTimestampValue } from '@duckdb/node-api';
const db = await DuckDBInstance.create(':memory:');
const connection = await db.connect();
await connection.run(`
CREATE TABLE IF NOT EXISTS test (
id BIGINT PRIMARY KEY,
value INTEGER NOT NULL,
timestamp TIMESTAMPTZ NOT NULL
);
`);
const query = await connection.prepare(
'INSERT INTO test (id, value, timestamp) VALUES ($1, $2, $3);',
);
// throws "bigint out of int64 range"
query.bindBigInt(1, BigInt(1));
// Works as expected
query.bindInteger(2, 100);
// throws "micros out of int64 range"
query.bindTimestamp(3, new DuckDBTimestampValue(BigInt(Date.now()) * 1000n));
await query.run();
const appender = await connection.createAppender('main', 'test');
// throws "bigint out of int64 range"
appender.appendBigInt(BigInt(2));
// Works as expected
appender.appendInteger(200);
// throws "Unimplemented type for cast (INT64 -> INT32)""
appender.appendTimestamp(new DuckDBTimestampValue(BigInt(Date.now()) * 1000n));
appender.endRow();
appender.close();
Specifications
- Version: 1.1.3-alpha.7
- Platform: Bun 1.1.38
- OS: Manjaro Linux, kernel 6.6.63-1-MANJARO
Interesting. I tested the above on Node v20.14.0 and it works fine. Perhaps this is something specific to Bun?
Sure enough, I ran the exact same script on the same machine using Bun, and it failed in the ways you describe. Could be a bug in Bun's implementation of the Node Addon API.
Yup, there's a TODO in the Bun code regarding the lossless
parameter of napi_get_value_bigint_int64
(and similar functions). This could definitely lead to some of the errors mentioned.
Asked about this in the relevant Bun issue.
Bun bug: oven-sh/bun#15797
Should be fixed in Bun v1.1.40.
Yes, it seems to be working as expected now. Thank you!
Thanks for the quick fix @190n!