# Upsert map in jsonb map array

**URL:** <https://forum.elixirforum.com/t/upsert-map-in-jsonb-map-array/26974>\
**Category:** Guides/Tuts/Tips/Info\
**Tags:** ecto, learning-elixir\
**Created:** [November 20, 2019, 2:26am UTC](https://forum.elixirforum.com/t/upsert-map-in-jsonb-map-array/26974 "2019-11-20T02:26:20Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![sorentwo](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/sorentwo/32/37360_2.png) [@sorentwo](https://forum.elixirforum.com/u/sorentwo)\
**Post date:** [November 21, 2019, 8:36am UTC](https://forum.elixirforum.com/t/upsert-map-in-jsonb-map-array/26974/5 "2019-11-21T08:36:30Z")

</div>

There are Postgres operators to do this directly on the jsonb column in an atomic way. You will need to use a fragment and play with the arguments a little bit.

The list of operators is [in the postgresql docs](https://www.postgresql.org/docs/current/functions-json.html). You are looking for `jsonb_set` in particular.

The Postgres adapter in my Flippant library has an example of doing upsert with an array on a jsonb column:

[https://github.com/sorentwo/flippant/blob/master/lib/flippant/adapters/postgres.ex#L79](https://github.com/sorentwo/flippant/blob/master/lib/flippant/adapters/postgres.ex#L79)

It is a bit complicated but works perfectly and is entirely atomic.

---

_[View the full topic](https://forum.elixirforum.com/t/upsert-map-in-jsonb-map-array/26974)._
