Is it possible to use the "unaccent" extension with drizzle?
hello, I wanted to make an ilike comparison in my query for the letter %á%, but it does not match for %Á%, because afaik, they are regarded as two different letters by postgres. I asked chatgpt, who told me to use the "unaccent" extension to remove the accents before the comparison to get good results. Is this really the way to go? If yes, how could I integrate it with drizzle? I just want to query usernames without worrying about casing :DD
15 Replies
managed to make it work on my own, I do not know if this is the recommended way, but it works atleast :DD
1. step: initialize the extension if it's not available when your app starts.
2. step: replace where clause in your query with custom sql using the unaccent function for the comparison.
3. step: have fun with your truly case-insensitive query results
Lol pretty genius I like it
Does postgres don't have collation? That's the mysql way
PostgreSQL Documentation
24.2. Collation Support
24.2. Collation Support # 24.2.1. Concepts 24.2.2. Managing Collations 24.2.3. ICU Custom Collations The collation feature allows specifying the sort order …
However, I am not sure how would you use this for the purpose mentioned?
You can tell the database how to compare accented and capitalized letters. You can make a = A and a = Ä return true depending on the collation. That way you don't need to use lower at all
PostgreSQL Documentation
24.2. Collation Support
24.2. Collation Support # 24.2.1. Concepts 24.2.2. Managing Collations 24.2.3. ICU Custom Collations The collation feature allows specifying the sort order …
Also, I believe you can use ILIKE clause to compare case insensitively
this depends on: https://github.com/drizzle-team/drizzle-orm/issues/638
GitHub
[FEATURE]: Support setting collation of columns · Issue #638 · driz...
Describe want to want Another fun Postgres feature! Let's say you're using fractional indexing and want to sort strings in a particular way that has nothing to do with their ordering in Eng...
until then, probably this solution is the most convenient dev exp
I would use collation, you can make it work with custom types
As soon as drizzle kit is released as OSS I would like to submit so many PRs, this might be one
How would you implement it? I am not sure how would I go about this
This is how I'm using custom types to create a generated column in one of my projects:
You can use the
dataType()
method to return the sql you need to create your column
In your case you'll replace as (concat_ws.....
with the collation you need