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

199
Views
How do I make a PG SQL ilike query in Javascript injection safe?

I want to have a simple search box in my web application using Javascript/Node.js and Postgresql. In it I have a form which is open for the public to make searches for names. I am not using any ORM so how do I make this type of search query safe in the backend, while using .then() ?

I want to use sort of SELECT * FROM spotters WHERE last_name ilike '%Burns%' but safely. The code below doesn't work, but how can I solve this? It feels like it should be quite easy.

// req.query.name = 'Burns' --- Could be "';DROP TABLE"!
pg_client.query("SELECT * FROM spotters WHERE last_name ilike '%?%'", [req.query.name])
  .then((sqlResult) => {
// handle result
  })

I want to have code similar to the above where it can ilike-search for column last name with a query received from the search input.

about 4 years ago · Juan Pablo Isaza
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!