objection.js: Error when using range() and whereJsonHasAny()

This works fine Model.query().whereJsonHasAny('someJsonField', 'someKey').then(...) but this doesn’t Model.query().range(0, 10).whereJsonHasAny('someJsonField', 'someKey').then(...) Here is the error: select count(*) as "count" from (select * from "Model" where "someJsonField"#>'{}' $1| array['someKey']) as temp - syntax error at or near "$1"

I think when range is making the count query it replaces ?| with$1| and causes the problem.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 16 (7 by maintainers)

Most upvoted comments

In knex you need to escape ? -mark

knex.raw(`SELECT * FROM "Model" WHERE "someJsonField"#>'{}' \\?| array['someKey']`).then();

I actually had to wrote the support to knex myself, when I was implementing json query stuff 😃