Add support in migrations for collations in Postgres#662
Conversation
|
Yes, a PR is welcome! |
|
Sorry, to be clear, yes please update this PR :) |
|
@josevalim I think this PR is ready for review. I did not add tests for modifying the collation on columns that have references to other columns. If you want I can look into that, but it requires some more SQL in between the DDL commands. |
| " COLLATE \"#{collation_name}\"" | ||
| end | ||
|
|
||
| defp collation_expr(_, _), do: [] |
There was a problem hiding this comment.
I think we should either raise or not check the type and let the underlying SQL operation fail. Perhaps the second option is best, because I don’t know if Postgres supports collations for custom types (which would then be impossible to check).
There was a problem hiding this comment.
Postgres does support collations for custom types, so letting the SQL fail is the best option.
| are not known by `ecto_sql` and specifying an incorrect collation might cause | ||
| a migration to fail. | ||
|
|
||
| ### N.B. be sure to match the collation on any columns that reference other text columns. See example below |
There was a problem hiding this comment.
Let’s convert this to a regular paragraph or admonition. Please also avoid abbreviations such as NB, i.e. and similar :)
|
thanks! :) |
I found this was missing when I added fractional indexes in my application. The default en_US-UTF8 collation will sort "Zy" after "a0". After setting the collation on the columns manually to "POSIX" the sorting worked as expected.
If there is interest to pull this into
ecto_sqlI will add documentation and support for MySQL and MSSQL as well.