I am trying to insert into the postgres using Elixir Ecto.Adapters.SQL.query, the query consists of array of tags which are strings. However it does inset into postgres, but not as a list of strings, but a single string. i.e. if tags contains ["abc","xyz"], it inserts in postgres as abcdef and not as array.
Important to mention, i am not using schema or migrations. Simple raw queries.
Map that needs to be inserted in postgres
response_map= %{"description" => "des33", "id" => 158,
"inserted_at" => "2017-06-09T10:19:03.904572", "tags" => ["abc","xyz"],
"title" => "test 1", "updated_at" => "2017-06-09T10:19:03.904578"}
Code that i use
%{"description" => desc, "id" => id, "title" => title, "tags" => tags}=response_map
Ecto.Adapters.SQL.query!(Repo,"insert into test values ('#{id}','#{title}','#{desc}','#{tags}')")
Ecto.Adapters.SQL.queryknow about Postgres array types? This is a Postgres specific feature, and if the query builder / SQL client doesn't know about this, it won't know how to treat it correctly.{ "tags": [ list of tags ] }. If you send it a serialized JSON object postgres will be smart enough to transform it into a JSON field, rather than leave it as a string.