Sqlx: LIKE queries using %

Created on 13 May 2015  路  1Comment  路  Source: jmoiron/sqlx

Hi,

Is there a good way to build queries with LIKE and %?
I would like to do something like this:

db.Select(&pp, "SELECT * FROM places WHERE LOWER(country) LIKE %?%", search)

I know I can concatenate % with search outside of the query, but I just ask if there is something better.

Most helpful comment

Hello,

You can embed the % in your query param, eg:

db.Select(&pp, "SELECT * FROM places WHERE lower(country) LIKE ?", "%"+search+"%"))

This should still be safe from injection attacks.

>All comments

Hello,

You can embed the % in your query param, eg:

db.Select(&pp, "SELECT * FROM places WHERE lower(country) LIKE ?", "%"+search+"%"))

This should still be safe from injection attacks.

Was this page helpful?
0 / 5 - 0 ratings