I am using Spring + Tomcat8 together with PostgreSQL 9.2. I installed the Trigram extension on the database for improved searching in tables.
When I connect to my database manually, the following statement works:
SELECT id, name, similarity(name, 'a') FROM dev.customer WHERE name % 'a' ORDER BY similarity ; However, when I try this in Spring using jdbcTemplate.query() I get an error:
PSQLException: ERROR: function similarity(character varying, character varying) does not exist When I remove the similarity() function and only use the % operator, I get the following exception:
ERROR: operator does not exist: character varying % character varying It seems that the postgres jdbc driver needs to be configured in order to support non-standard syntax: https://jdbc.postgresql.org/documentation/81/ext.html
The server.xml of my tomcat installation contains the following resource:
<Resource name="jdbc/NasPostgresDB" auth="Container" type="javax.sql.DataSource" username="usr" password="pwd" url="jdbc:postgresql://127.0.0.1/dbname" driverClassName="org.postgresql.Driver" initialSize="5" maxWait="5000" maxActive="120" maxIdle="5" validationQuery="select 1" poolPreparedStatements="true"/> which should be correct: https://jdbc.postgresql.org/documentation/81/load.html
What exacly do I need to do to make trigram matching working?
select current_database(), current_schema(), current_schemas(true), current_user, inet_client_addr(), inet_client_port(), inet_server_addr(), inet_server_port(), pg_my_temp_schema(), pg_postmaster_start_time(), session_user, version();executed twice: once in psql and once from java code from your application?"sapling , , {pg_catalog} , postgres , 192.168.0.13 , 20290 , 192.168.0.3 , 5432 , 0 , "2015-05-21 12:00:20.422757+02" , postgres , "PostgreSQL 9.1.15 on x86_64-unknown-linux-gnu , compiled by gcc (Debian 4.7.2-5) 4.7.2 , 64-bit""Result from java:sapling , , {pg_catalog} , postgres , 192.168.0.13 , 19955 , 192.168.0.3 , 5432 , 0 , "2015-05-21 12:00:20.422757+02" , postgres , "PostgreSQL 9.1.15 on x86_64-unknown-linux-gnu , compiled by gcc (Debian 4.7.2-5) 4.7.2 , 64-bit"JDBC41 Postgresql Driver, Version 9.4-1201driver from the postgres HP: jdbc.postgresql.org/download.html