-
i want to find any name that contains string 'hy' or any othe string in then. So, i test the query, directly on the database like this: SELECT * FROM namelist
WHERE name LIKE '%hy%' and it works. then i tried in in prepared statement, like this: let name = "hy"
sqlx::query_as(r#"SELECT * FROM namelist WHERE name LIKE '%$1%'"#)
.bind(name)
.fetch_all(pool)
.await; it returns empty. What did i do wrong. I can't find anything on the internet on how i can do this. |
Beta Was this translation helpful? Give feedback.
Answered by
newholder
May 30, 2024
Replies: 1 comment
-
Human error, Just put the percentage in the bind, so let name = "%hy%"
sqlx::query_as(r#"SELECT * FROM namelist WHERE name LIKE $1"#)
.bind(name)
.fetch_all(pool)
.await; |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
newholder
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Human error, Just put the percentage in the bind, so