DEV Community

juffel
juffel

Posted on

1

Ecto: Create a case insensitive unique index

Today I learned that Ecto.Migration supports this out of the box 🥳

You probably know that you can easily create a unique index like this:

create unique_index("products", [:name], name: :products_lower_name_index)
Enter fullscreen mode Exit fullscreen mode

But did you also know that you can do this also in a case-insensitive way?
According to the docs you can not only provide column names for a new unique index, but also a custom expression.

# Create an index on a custom expression
create unique_index("products", ["(lower(name))"], name: :products_lower_name_index)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay