Search code examples
elixirphoenix-frameworkecto

How to store two dimension array of string in Elixir Ecto. How to put matching length to list?


How do I save 2d lists into postgres? Or put matching lengths to lists?

I tried this in my migration..

  add :checkpoints, {:array, :string}

and schema..

  field :checkpoints, {:array, {:array, :string}}

But when i save this sample value of [["C23", "E12"], ["N34"], ["G22"]] to :checkpoints field, I get this error:

(ArgumentError) nested lists must have lists with matching lengths

Solution

  • All of our lists need to have the same length. Your first list has three elements, the other ones have only 1.