duckdb / duckdb-node

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Prepared statements don't accept list arguments

tronis470 opened this issue · comments

I can't pass a list/array as an argument into prepared statements with duckdb-node 0.9.2. Try this script:

const { Database } = require("duckdb");

const db = new Database(":memory:");
const conn = db.connect();

const stmt1 = conn.prepare("select ?::INTEGER as fortytwo");
stmt1.all(42, (err, res) => {
  if (err) {
    throw err;
  }
  console.log(res);
});

// throws error
const stmt2 = conn.prepare("select unnest(?::VARCHAR[]) as x");
stmt2.all(["a", "b", "c"], (err, res) => {
  if (err) {
    throw err;
  }
  console.log(res);
});

// throws error
const stmt3 = conn.prepare("select unnest(?) as x");
stmt3.all(["a", "b", "c"], (err, res) => {
  if (err) {
    throw err;
  }
  console.log(res);
});

// throws error
const stmt4 = conn.prepare("select unnest(?) as x");
stmt4.all([["a", "b", "c"]], (err, res) => {
  if (err) {
    throw err;
  }
  console.log(res);
});

Depending on which version you try, you get errors like:

Error: Type VARCHAR with value 'a,b,c' can't be cast to the destination type LIST

or

Error: Binder Error: UNNEST() can only be applied to lists, structs and NULL