# Convert string column to integer in DB

**URL:** <https://forum.elixirforum.com/t/convert-string-column-to-integer-in-db/38521>\
**Category:** Questions\
**Tags:** ecto, phoenix, ecto-migration\
**Created:** [March 27, 2021, 4:04pm UTC](https://forum.elixirforum.com/t/convert-string-column-to-integer-in-db/38521 "2021-03-27T16:04:26Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![benwilson512](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/benwilson512/32/1457_2.png) [@benwilson512](https://forum.elixirforum.com/u/benwilson512)\
**Post date:** [March 27, 2021, 4:47pm UTC](https://forum.elixirforum.com/t/convert-string-column-to-integer-in-db/38521/9 "2021-03-27T16:47:12Z")

</div>

So what is the point in converting it into an integer then? OH! You’re trying to use ecto\_enum library. Just use the built in [Ecto.Enum — Ecto v3.14.0](https://hexdocs.pm/ecto/Ecto.Enum.html) type. It works fine with strings.

EDIT: If you’re trying to get the sortability property, I would seriously just consider using a proper database enum type and not trying to convert into integers.

IF however you really want to do this, here is how:

1. Make a new column of type integer called `new_column_name`.
2. Run a series of updates:

```elixir
update table_name set new_column_name = 0 where column_name = "verifiy"
update table_name set new_column_name = 1 where column_name = "invite"
... etc

```

1. Drop the old column and rename the new column to column.

---

_[View the full topic](https://forum.elixirforum.com/t/convert-string-column-to-integer-in-db/38521)._
