Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

283
Views
How to apply LOWER() to a ref in Objection

Im using a like where statement in my query like this:

import { ref } from 'objection'

// [...]

query = query.where(ref('data.nested_data').castText(), 'like', `%${value}%`)

And its working fine. The resulting query looks like this:

WHERE CAST("data"#>>'{nested_data}' AS text) like '%example%'

Now I want to use LOWER() funcion in the key, so I can find results case-insensitive. So my query now looks like this:

import { ref, raw } from 'objection'

// [...]

query = query.where(raw(`LOWER(${ref('data.nested_data').castText()})`), 'like', `%${value.toLowerCase()}%`);

But this results to the following SQL query (throwing an error):

WHERE LOWER([object Object]) like $1

-- ERROR:  syntax error at or near "["
-- LINE 6: WHERE LOWER([object Object]) like $1

Is there any way to achieve what Im looking for? I prefer not using a raw query since my type to cast is dynamic

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The people maintaining Objection helped me solving this issue at github.

The correct syntax is:

const key = ref('data.nested_data').castText();
query = query.where(raw('LOWER(??)', [key]), 'like', `%${value.toLowerCase()}%`);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!