Full text search and variable binding using postgres and jOOQ do not work

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 a variable binding to protect against SQL injection, I no longer get the results:

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

Any ideas?

Thanks and good afternoon

+6
source share
1 answer

Since @posz did not post my comment as an answer, and quite a while has passed, I myself will send my answer as an answer for clarity.

Try ... to_tsquery (?) ... - anchor sign? will not work inside literal.

0
source

All Articles