Use smaller string column than varchar255

I want to create a column in one of the tables with a varchar2 and not more than that. By default string in ecto migration refers varchar255. So how can I use varchar2?

In migration simply write: :"varchar(2)" as a type or "varchar(2)" in latest ecto_sql (as String was not supported before).

Thank you :slight_smile:

You can also use the size option in the migration. Here’s an example from the ecto_sql tests:

https://github.com/elixir-ecto/ecto_sql/blob/da96dad6275cec53541463ae057bb6c0ec49783b/test/ecto/adapters/postgres_test.exs#L1179

Note how name is generated as a VARCHAR(20).

Ah, completely forgot about this option, nice find. In that case it’s worth to give some links to official API:

Each of those 3 mentions :size option. Both add/3 and modify/3 provides more useful options:

Thank you. This is a more clean option :slight_smile: