6

I am trying to run the query:

let query =
    `
        DELETE FROM
            ${table_name}
        WHERE
            _id IN ($1::bigint[])
            AND
            account_id = $2
    `
let fields =
    [
        _ids,
        account_id,
    ]

but it's giving me the error:

operator does not exist: bigint = bigint[]

_ids is an array.

NOTE

The error I was getting once implementing the answer was:

GraphQLError: Int cannot represent non-integer value: []

This was simply a GraphQL error, nothing to do with postgres.

vitaly-t
  • 24,279
  • 15
  • 116
  • 138
A. L
  • 11,695
  • 23
  • 85
  • 163

1 Answers1

11

The IN operator expects either a set of rows with exactly one column, or a parenthesized list of scalar expressions. It doesn't accept an array.

One answer suggests :list, which tells pg-promise to do the right thing:

WHERE _id IN ($1:list)

Another answer suggests = any, where ANY is a Postgres operator that does accept arrays:

WHERE _id = ANY ($1::int[])
Andomar
  • 232,371
  • 49
  • 380
  • 404
  • for either example, I'm getting the error: `GraphQLError: Int cannot represent non-integer value: []` and shouldn't it be bigint? Since the `_id` is `bigserial` – A. L Feb 10 '19 at 01:24
  • this was actually the answer. The issue I was getting was GraphQL's error zzz. – A. L Feb 10 '19 at 04:46