Skip to content

Using % with ILIKE operator #134

Open
@lucasl84

Description

@lucasl84

Hi,

Just wanted to ask something I'm not fully getting. I'm having trouble on how to correctly use the ILIKE operator with the % wildcard. I have a table orders with a TEXT field named item_id. This works:

await db.all("SELECT * FROM orders WHERE item_id ILIKE ?;", item)

Adding the % wildcard in any of the following ways will fail:

await db.all("SELECT * FROM orders WHERE item_id ILIKE %?;", item)
await db.all("SELECT * FROM orders WHERE item_id ILIKE ?%;", item)
await db.all("SELECT * FROM orders WHERE item_id ILIKE %?%;", item)

The error is the same for the 3 examples:

[Error: Parser Error: syntax error at or near "%"] {
  errno: -1,
  code: 'DUCKDB_NODEJS_ERROR',
  errorType: 'Parser'
}

Adding single quotes for any of the % expressions above does not solve the issue.

Another similat issue that I'm getting is when I try to perform a SELECT with the IN operator. Given an array of ids, e.g: [1, 2, 3] How should I correctly write/pass arguments to db.all?:

let orders = [1, 2, 3];
await db.all("SELECT * FROM batches WHERE order_id IN (?);", orders);

The above snippet produces the following error:

[Error: Conversion Error: Could not convert string '1,3,6' to INT64] {
  errno: -1,
  code: 'DUCKDB_NODEJS_ERROR',
  errorType: 'Conversion'
}

Is there any documentation on how to write these types of queries?

Thanks in advance,
Lucas.

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