# Postgres column type for embeds\_many

**URL:** <https://forum.elixirforum.com/t/postgres-column-type-for-embeds-many/11422>\
**Category:** Questions\
**Tags:** ecto, jsonb, postgres\
**Created:** [January 9, 2018, 3:04pm UTC](https://forum.elixirforum.com/t/postgres-column-type-for-embeds-many/11422 "2018-01-09T15:04:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jyurek](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jyurek/32/7633_2.png) [@jyurek](https://forum.elixirforum.com/u/jyurek)\
**Post date:** [January 9, 2018, 3:04pm UTC](https://forum.elixirforum.com/t/postgres-column-type-for-embeds-many/11422/1 "2018-01-09T15:04:13Z")

</div>

Everywhere I’ve seen a blog post, etc. about making a column in postgres for an `embeds_many`, I see the same advice: use `add :column, {:array, :map}, default: []` in the migration.

But this creates a postgres array of jsonb objects. This is not sensible to query on.

In my testing, I’ve found that simply using a `:jsonb` type for the column is sufficient and correct for everything `embeds_many` can do. It can leverage all the power of postgres’ jsonb type as well.

So here’s the question: If everyone is suggesting `{:array, :map}` and that seems to be inadequate for the purposes of doing standard database things, am I wrong for using `:jsonb`? Is there something about this that I’m overlooking?

---

<div class="post-metadata">

**Author:** ![JanStevens](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/janstevens/32/3601_2.png) [@JanStevens](https://forum.elixirforum.com/u/JanStevens)\
**Post date:** [May 8, 2018, 2:17pm UTC](https://forum.elixirforum.com/t/postgres-column-type-for-embeds-many/11422/2 "2018-05-08T14:17:35Z")

</div>

I have exactly the same question, I spend a couple of hours on this since I noticed that with `{:array, :map}` the data is not stored as JSON but as a JSON string!

Seems that there is something mixed up. What I do know is that `{:array, :map}` is the adapter generic way of saying you want to store embedded records independent of the database you are using. For Postgres this should map to JSONB but apparently it does not or does in a strange way.

---

<div class="post-metadata">

**Author:** ![LostKobrakai](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lostkobrakai/32/3072_2.png) [@LostKobrakai](https://forum.elixirforum.com/u/LostKobrakai)\
**Post date:** [May 8, 2018, 2:27pm UTC](https://forum.elixirforum.com/t/postgres-column-type-for-embeds-many/11422/3 "2018-05-08T14:27:55Z")

</div>

[https://robots.thoughtbot.com/why-ecto-s-way-of-storing-embedded-lists-of-maps-makes-querying-hard](https://robots.thoughtbot.com/why-ecto-s-way-of-storing-embedded-lists-of-maps-makes-querying-hard)

tldr: it’s suggested because of older postgres version support
