shijith.k
I have a varchar field in my table. It has values like verify and invite. I want to use enum instead of this, and I am planning to use Ecto Enum. Now to do that I want to convert the varchar field to integer. How can I write a query to change the existing string values to integer values?
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Kia ora,
We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Hello,
I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter).
The diffic...
New
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
Other Trending Topics
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
ICal is a library for interacting with iCalendar data. It parses iCalendars into typed Elixir structs via ICal.from_ics, and can prepare ...
New
Latest Phoenix Threads
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #ai
- #phoenix_html
- #elixirconf-us
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
APB9785
Make a new migration file (in priv/repo/migrations) like:
Then run mix ecto.migrate
WestKeys
I believe that would remove all the data under
:column_nameYou can use modify/3
But you still need to handle typecasting the actual data in that column
See this thread Ecto Changeset: modify column type from :string to {:array, :string}
APB9785
That’s right. I assumed the app was not in production yet. If the data needs to be preserved, then disregard my reply.
shijith.k
This is a destructive migration. This will actually create more problems than solution
shijith.k
This helps.But it doest solve my issue completely. I my case, each different value should be converted to a different integer.
For example:
verify→ 1invite→ 2This is how I need to convert the field.
As you can already assume, I am not really an expert in SQL. So I don’t know how to update the query in the thread you shared in such way that it solves my problem
benwilson512
Are you trying to convert this into an actual database enum? If so, this should be relevant: https://stackoverflow.com/questions/15655820/upgrading-a-varchar-column-to-enum-type-in-postgresql
shijith.k
Not really. Using an database enum might be problematic as its suggested in the comments of the stack overflow question. I am trying to make use of EctoEnum to leverage similar use cases of a db enum.
benwilson512
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 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:
new_column_name.shijith.k
Thanks
this helps
shijith.k
Still, out of curiosity, if I want to convert it in to integer - how can I do it?