How to store array with Ecto using Postgres
I found the answer in the list of primitive types for Ecto.Schema here:
Ecto.Schema
The answer is to define the type like this:
schema "my_model" do
field :my_array, {:array, :float}
timestamps
end
As Josh wrote use the array type from Ecto.Schema
In the model:
schema "my_model" do
field :my_array, {:array, inner_type}
end
@neildaemond Migration:
alter table(:my_models) do
add :my_array, {:array, inner_type}
end
Replace inner_type
with one of the valid types, such as :string
.
You can also do the same thing with a map
type:
schema "my_model" do
field :my_map, {:map, inner_type}
end