I have filed the bug in spring-data-jdbc that describes the problem in details. I am linking it here for you to understand the context: https://github.com/spring-projects/spring-data-relational/issues/1556.
Long story short, when using spring-jdbc
module, in particular NamedPrarameterJdbcTemplate
API, there are cases, when parameters in single quotes should be interpreted as parameters and should not be leaved as-is. I have explain the real case we encountered using PostreSQL specific dialect.
The problem is that spring-data-relational
uses NamedPrarameterJdbcTemplate
under the hood to execute queries, so here we have a problem.
What I can think of is this:
- Consider to use some sort of escaping here, like in BRE/ERE RegExp.
- Maybe add specific parameter to
NamedParameterJdbcTemplate
andJdbcTemplate
API methods, likeParameterSubstitutionPolicy
.
So, it would be great if we will have a way to configure spring in some cases to treat parameters in single quotes as real parameters, not a plain text.
Comment From: snicoll
@Mikhail2048 I am not sure what we could do about this to be honest. The current behavior is expected (https://github.com/spring-projects/spring-data-relational/issues/1556#issuecomment-1628393985) and changing it for a Postgres-specific syntax does not sound appealing.
I suggest to not use a named parameter for this query.