Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Full text search and variable binding using postgres and jOOQ not working

I am trying to do a full text search in a postgres database using jOOQ. The following line works:

Result res = pgContext.select()
                      .from(products.PRODUCTS)
                      .where("to_tsvector(title || ' ' || description || ' ' || tags) @@ to_tsquery('" + query + "')")
                      .fetch();

But when I add variable binding, to protect from SQL injection, I no longer get results:

Result res = pgContext.select()
                      .from(products.PRODUCTS)
                      .where("to_tsvector(title || ' ' || description || ' ' || tags) @@ to_tsquery('?')", query)
                      .fetch();

Any ideas?

Thanks and good day

like image 460
Dries De Rydt Avatar asked Jun 14 '16 12:06

Dries De Rydt


1 Answers

Since @posz did not post his comment as an answer, and it has been quite a while, I'll post his reply as an answer myself for clarity.

Try ... to_tsquery(?) ... -- the binding mark ? won't work inside a literal.

like image 169
Dries De Rydt Avatar answered Oct 10 '22 13:10

Dries De Rydt