Accent characters
Postgres comes with many default extensions and they have one for dealing with accent characters.
We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
You might have a need to remove accents from names or words from your application. Especially if you are trying to create a slug out of that name.
Postgres comes with so many default extensions that are turned off. And they have an extension that deals with accents called unaccent
Just log into your postgres console and type this query
> psql
> select * from pg_available_extensions;
...
You will see a long table of available extensions.
As usual, reading the documentation is the best way to understanding how the extension works. In this example we want the unaccent
extension.
The Postgres documentation explains how it works.
If I want to run a migration in postgres or Phoenix to turn this on, I would create the following migration.
defmodule Pomotv.Repo.Migrations.AddAccentExtension do
use Ecto.Migration
def change do
execute """
CREATE EXTENSION unaccent;
"""
end
def down do
execute """
DROP EXTENSION unaccent;
"""
end
end
In your migration: file when you want to perform database specific actions you need to use the execute
function as shown above.
As always make sure your down
function is able to undo, just in case you need to rollback.