electric-sql / pglite

Lightweight WASM Postgres with real-time, reactive bindings.
https://pglite.dev
Apache License 2.0
9.49k stars 204 forks source link

For null, bigint Query fails with error "inconsistent type deduced for parameter" for null and bigint #349

Closed ackava closed 1 month ago

ackava commented 2 months ago

Tested with version 0.2.8

Passing null to timestamp column fails.

   pg.sql `create table mb( id bigint, updated timestamp null, primary key(id) )`;

   const mb = { id: 1, updated: null };

   pg.query ("insert into mb(id, updated) values ($1, $2)", mb.id, mb.updated) ;

Passing 1 to bigint column fails.

   pg.sql `create table mb( id bigint, updated bigint null, primary key(id) )`;

   const mb = { id: 1, updated: 1 };

   pg.query ("insert into mb(id, updated) values ($1, $2)", mb.id, mb.updated) ;

Error Detail,

index.ts:586 error: inconsistent types deduced for parameter $2
    at me.Ce (https://cdn.jsdelivr.net/npm/@electric-sql/pglite@0.2.8/dist/chunk-AZTFRW3V.js:1:12465)
    at me.je (https://cdn.jsdelivr.net/npm/@electric-sql/pglite@0.2.8/dist/chunk-AZTFRW3V.js:1:9851)
    at me.parse (https://cdn.jsdelivr.net/npm/@electric-sql/pglite@0.2.8/dist/chunk-AZTFRW3V.js:1:8603)
    at H.execProtocol (https://cdn.jsdelivr.net/npm/@electric-sql/pglite@0.2.8/dist/index.js:1:6241)
    at async Object.execProtocol (https://cdn.jsdelivr.net/npm/@electric-sql/pglite@0.2.8/dist/worker/index.js:1:6990)
    at async BroadcastChannel.<anonymous> (https://cdn.jsdelivr.net/npm/@electric-sql/pglite@0.2.8/dist/worker/index.js:1:6564)
samwillis commented 2 months ago

Hey @ackava, thanks for the report, although I'm struggling to reproduce it.

There's a couple of typos in your comment, it's missing the array wrapper around the params. But thats not the error, and adding them doesn't trigger the error you've posted. It looks like you've used the worker, I've tried it with that too.

ackava commented 2 months ago

@samwillis I was able to figure out the issue, column was set to text and I was trying to insert a number. Usually postgres (node pg) reports an error such as unable to convert number to text/varchar. However in non worker mode, this returns a different error such as Insufficient data left in message.

https://jsfiddle.net/0kzu3y1v/14/

Will it be possible to improve the error message?