prisma: Cannot filter using accent Insensitive

Bug description

I’ve looked in all the places trying to find a way to use {where: {field: {contains: 'João' } } and retrieve all the results without matching of accents,

The result I expect: i.e : João = Joao

I’ve tried to add a collation that ignore accents manually in the field that I’m searching, like this:

// Creating the collation
CREATE COLLATION ignore_accent (provider = icu, locale = 'und-u-ks-level1-kc-true', deterministic = false);

// Creating the table with the collation already applied in the field
CREATE TABLE "protocols" (
    "id" SERIAL NOT NULL,
    "title" TEXT NOT NULL COLLATE ignore_accent,

    CONSTRAINT "protocols_pkey" PRIMARY KEY ("id")
);

But It is showing me this error

ConnectorError(ConnectorError {
 user_facing_error: None, kind: QueryError(Error {
 kind: Db, cause: Some(DbError { severity: "ERROR", 
parsed_severity: Some(Error), code: SqlState(E0A000), 
message: "nondeterministic collations are not supported for ILIKE", detail: None, hint: None, position: None, where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: Some("like.c"), line: Some(199), routine: Some("Generic_Text_IC_like") 
}) }) })

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 3
  • Comments: 17 (1 by maintainers)

Most upvoted comments

Being able to filter by ignoring accent is key also in France 😃 Search is not usable without supporting this extension 😦 Making complex search and filter queries with raw queries is complicated for someone who need an ORM to avoid manipulating SQL raw queries 😃

image This was his answer And my implementation:
const name = 'Sóstenes Apollo';
const filterText = removeAccents(`%${name}%`).toLowerCase();
console.log('Filter text', filterText);

this.prisma.$queryRaw`select 
    id, name 
  from users 
    where LOWER(unaccent(name)) LIKE ${filterText};`.then((users) =>
  console.log(users),
);

ps. note that the removeAccents method will return like: Sostenes Apollo, so I just pick it and make it lower to be like: sostenes apollo

It’s a shame, they don’t deserve to be called developers

need this so bad !

It’s a shame, they don’t deserve to be called developers

Well that’s a bit harsh and not fair, remember it’s open source software. But I agree with @matmkian (I’m french too) and without this, it’s difficult to consider prisma as properly useable.

I created a migration to handle with this issue

-- DropForeignKey
DROP EXTENSION IF EXISTS unaccent;

-- AddForeignKey
CREATE EXTENSION unaccent;

Unfortunately, this only works with query raw!

CREATE EXTENSION unaccent; You should use this command if you’re using postgres.

I think if you switch to mysql you’ll be able to run with your custom collation or something like this

@NikitaMasl yeah, I’ve tried everything you can imagine, and it seems to be a prisma limitation

This version @Jolg42 "@prisma/client": "^3.15.2"

prisma                  : 3.15.2
@prisma/client          : 3.15.2
Current platform        : darwin-arm64
Query Engine (Node-API) : libquery-engine 461d6a05159055555eb7dfb337c9fb271cbd4d7e (at node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Migration Engine        : migration-engine-cli 461d6a05159055555eb7dfb337c9fb271cbd4d7e (at node_modules/@prisma/engines/migration-engine-darwin-arm64)
Introspection Engine    : introspection-core 461d6a05159055555eb7dfb337c9fb271cbd4d7e (at node_modules/@prisma/engines/introspection-engine-darwin-arm64)
Format Binary           : prisma-fmt 461d6a05159055555eb7dfb337c9fb271cbd4d7e (at node_modules/@prisma/engines/prisma-fmt-darwin-arm64)
Default Engines Hash    : 461d6a05159055555eb7dfb337c9fb271cbd4d7e
Studio                  : 0.462.0
Preview Features        : interactiveTransactions