Remove trailing space (from column length) in ecto

i have character column type with length 30, when i do Repo.insert, ecto change uncomplete of column length as space,

column length 30
6282837022479+++++++++++++++++ given value is 6282837022479

how do i remove that trailing space ?, thank you

ps : i can’t write trailing space here

I think you have three strategies you could try:

  1. Change the database column type to VARCHAR(30). CHAR(30) enforces a length of 30 which is why you have the trailing spaces. I think this is the preferred model

  2. Use String.trim_trailing(column, " ") after you do any database operations.

  3. Implement a customer Ecto type that does the trimming for you (but not really the best use of a customer type)

2 Likes

thank you !, i’m new in postgres and still mixed up with the data type :+1: