sfackler / rust-postgres

Native PostgreSQL driver for the Rust programming language
Apache License 2.0
3.43k stars 436 forks source link

Quoted Strings with LIKE in tokio_postgres. #1173

Closed cuyler closed 3 weeks ago

cuyler commented 3 weeks ago

This is probably a silly question but for the life of me, I can't see it. How does one execute statements with LIKE as part of the query? Postgresql sees a difference between '"Foo"%' (or '"Foo%"') and 'Foo%' in the context of LIKE. It's understandable to use quoted strings for sql injection prevention, however it's unclear how to use a LIKE statement with those parameters... Is there an alternative canonical way to accomplish this with tokio_postgres?

sfackler commented 3 weeks ago

What do you mean by "quoted strings"? Query parameters are not inlined into the query, they're sent separately. I would expect something like this to work just fine:

let rows = client.query("SELECT name FROM foo WHERE name LIKE $1", &[&"Foo%"]);`

and would return values like Foobar.

cuyler commented 3 weeks ago

Aye; Thanks for the rubber ducking and apologies for the time waster. I didn't think to check the input, which WAS quoted. Doh.