Advertisement
Hen_B_S

Ignore Accent in Query

Jul 30th, 2024
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.02 KB | Source Code | 0 0
  1. PostgresSQL
  2. Note : Enable unaccent extension in your database :
  3. CREATE EXTENSION unaccent;
  4.  
  5. @Query(nativeQuery = true, value = "SELECT * FROM schema_name.table_name "
  6.                                  + "WHERE unaccent(col_name) = unaccent(:name)")
  7. public List<EntityName> find(@Param("name") String name);
  8.  
  9. MySQL
  10. For those who use MySQL you can use collate utf8_bin Like this :
  11.  
  12. @Query(nativeQuery = true, value = "SELECT * FROM table_name "
  13.                                  + "WHERE col_name = :name collate utf8_bin")
  14. public List<EntityName> find(@Param("name") String name);
  15.  
  16. SQL Server
  17. For those who are using Oracle you can use collation
  18.  
  19. @Query(nativeQuery = true, value = "SELECT * FROM table_name WHERE "
  20.         + "name COLLATE Latin1_general_CI_AI Like :name COLLATE Latin1_general_CI_AI")
  21. public List<EntityName> find(@Param("name") String name);
  22.  
  23. References :
  24. Does PostgreSQL support "accent insensitive" collations?
  25. How do I perform an accent insensitive compare (e with è, é, ê and ë) in SQL Server?
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement