0
// server.js (only my query route)
app.get("/rocket/search/:query", async (req, res) => {
    try {
        const { query } = req.params;
        const rocket = await pool.query("SELECT * FROM rocket WHERE name ILIKE $1", // Query
        [ query ]
        );

        res.json(rocket.rows);
    } catch (err) {
        console.log(err.message);
        console.log("test")
    }
})

When making a request using the above query It yields results that ignore differences in capitalization so that works okay. But when making a query to the name field such as "starshi" when the actual name is "Starship" I get no results.

What's going wrong?

Thanks

JackMcz
  • 11
  • 3
  • By default `LIKE/ILIKE` matches the entire string. To get what you want: `select 'Starship' ilike 'starshi%'; t`. See here [LIKE](https://www.postgresql.org/docs/14/functions-matching.html#FUNCTIONS-LIKE) for more details. – Adrian Klaver Feb 26 '22 at 16:30
  • Thank you both, This helped and I used the following to help with my specific use case [NODE SQL](https://stackoverflow.com/questions/19471756/how-to-make-a-like-search-in-postgresql-and-node-js) – JackMcz Feb 26 '22 at 18:29

0 Answers0