I have a query in format
namedJdbcTemplate.queryForObject("""
select * from table
where column = 'somethins :param'
""", new MapSqlParameterSource('param', someValue), someReturnType);
How can i make it inject the param value into the string?
This is a simplified case. Actual usecase uses a function on DB side to construct a complex query, all im giving it is a where clause and params for the where clause:
namedJdbcTemplate.queryForObject("""
select myfunc($$%s$$)
""".formatted(getFilterClauseFromDB()), params, someReturnType);
When the formatting does its work it should look something like this
namedJdbcTemplate.queryForObject("""
select myfunc($$AND val1 = :val1 and val2 = :val2 $$)
""", params, someReturnType);
where params is a Map<string, object> of parameters parsed by a generic parameter parsing system to put them into correct format. But the namedJDBCTemplate does not map parameters to :val1 and :val2 for some reason. Function intenrally runs a postgres crosstab function. Even if i do away with my function the issue remains. I need to inject parameters into a string that is inside SQL since crosstab accepts queries in the format of string.
Somehow i need to get the params placed into the filterclause that is a string that is built on the runtime. Is there a way i can do it? Currently it throws error The column index is out of range: 1, number of columns: 0