I have a query on these lines where I am trying to filter out a result set by comparing tuples (for example, several SQL columns in the IN section ):
select * from mytable where (key, value) in (values ('key1', 'value1'), ('key2', 'value2'), ... );
This is a valid syntax and works fine in my Postgres 9.3 database.
I want to call this query through Spring JDBC, where the pairs of in values ββare taken from List<Map<String,String>> .
It would be nice to do something like this:
List<Map<String, String>> valuesMap = ...; String sql = "select * from mytable where (key, value) in (values :valuesMap)"; SqlParameterSource params = new MapSqlParameterSource("valuesMap", valuesMap); jdbcTemplate.query(sql, params, rowMapper);
When I try to do this, I get:
org.postgresql.util.PSQLException: No hstore extension installed. at org.postgresql.jdbc2.AbstractJdbc2Statement.setMap(AbstractJdbc2Statement.java:1707) ~[postgresql-9.3-1101-jdbc41.jar:na] at org.postgresql.jdbc2.AbstractJdbc2Statement.setObject(AbstractJdbc2Statement.java:1910) ~[postgresql-9.3-1101-jdbc41.jar:na] at org.postgresql.jdbc3g.AbstractJdbc3gStatement.setObject(AbstractJdbc3gStatement.java:36) ~[postgresql-9.3-1101-jdbc41.jar:na] at org.postgresql.jdbc4.AbstractJdbc4Statement.setObject(AbstractJdbc4Statement.java:47) ~[postgresql-9.3-1101-jdbc41.jar:na] at org.springframework.jdbc.core.StatementCreatorUtils.setValue(StatementCreatorUtils.java:427) ~[spring-jdbc-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.jdbc.core.StatementCreatorUtils.setParameterValueInternal(StatementCreatorUtils.java:235) ~[spring-jdbc-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.jdbc.core.StatementCreatorUtils.setParameterValue(StatementCreatorUtils.java:150) ~[spring-jdbc-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.jdbc.core.PreparedStatementCreatorFactory$PreparedStatementCreatorImpl.setValues(PreparedStatementCreatorFactory.java:287) ~[spring-jdbc-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.jdbc.core.PreparedStatementCreatorFactory$PreparedStatementCreatorImpl.createPreparedStatement(PreparedStatementCreatorFactory.java:244) ~[spring-jdbc-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:623) ~[spring-jdbc-4.2.3.RELEASE.jar:4.2.3.RELEASE]
I looked at the hstore extension that he mentions. This is not like my problem.
Is there a way to accomplish this without dynamically building the SQL list and parameters?
source share