I\'m working with Go and PostgreSQL (pq driver), I have the following query
SELECT p.id, p.name, p.description, p.price, p.image, p.rate
FROM products AS p
W
According to this issue your query must not contain '%' sign, but "name" parameter must be quoted by '%'
query := `SELECT p.id, p.name, p.description, p.price, p.image, p.rate
FROM products AS p
WHERE LOWER(p.name) LIKE $1 ORDER BY p.rate DESC`
product_rows, err := db.Query(query, fmt.Sprintf("%%%s%%", name))
Dont put qoutes when you are preparing your query. Just provide the value with qoutes and % sign. This will solve the problem. tried and tested.
Solution:
query := SELECT p.id, p.name, p.description, p.price, p.image, p.rate
FROM products AS p
WHERE LOWER(p.name) LIKE $1 ORDER BY p.rate DESC
product_rows, err := db.Query(query, "'%" + name + "%'")
I got my soltion from this thread
You need to put the like
pattern in single quotes:
SELECT p.id, p.name, p.description, p.price, p.image, p.rate
FROM products AS p
WHERE LOWER(p.name) LIKE '%' || $1 || '%'
ORDER BY p.rate DESC;