<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="110941" data-post-id="110941">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="mischov" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/mischov/120/2489_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  mischov
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Yeah, creating a type is a solution- something similar (but different) to this will likely work.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule Type.Json do
  @behaviour Ecto.Type
  @moduledoc """
  To store values that might be any json value.

  Not intended as a general replacement for :map.
  """

  def type, do: :json

  def cast(value) when is_nil(value), do: {:ok, value}
  def cast(value) when is_boolean(value), do: {:ok, value}
  def cast(value) when is_binary(value), do: {:ok, value}
  def cast(value) when is_number(value), do: {:ok, value}
  def cast(value) when is_list(value), do: {:ok, value}
  def cast(value) when is_map(value), do: {:ok, value}
  def cast(_), do: :error

  def load(data), do: {:ok, data}

  def dump(value) when is_nil(value), do: {:ok, value}
  def dump(value) when is_boolean(value), do: {:ok, value}
  def dump(value) when is_binary(value), do: {:ok, value}
  def dump(value) when is_number(value), do: {:ok, value}
  def dump(value) when is_list(value), do: {:ok, value}
  def dump(value) when is_map(value), do: {:ok, value}
  def dump(_), do: :error
end
</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="110941" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/insert-string-integer-map-list-in-a-jsonb-postgresql-column/19276/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-110941" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="110941"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="110943" data-post-id="110943">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Eiji" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Eiji/120/36743_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Eiji
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><a class="mention" href="/u/mischov" rel="nofollow">@mischov</a>: Unfortunately it’s probably not enough. You would need to do all <code>is_*</code> checks (except <code>is_list</code> and <code>is_map</code>) on all <code>List</code> elements and <code>Map</code>. Notice that somebody could type map with for example <code>Atom</code> as value. In such way encoding could not work as expected.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="110943" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/insert-string-integer-map-list-in-a-jsonb-postgresql-column/19276/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-110943" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="110943"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #12"></div>
  </section>
</div>
    <div class="postbit" id="110944" data-post-id="110944">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="mischov" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/mischov/120/2489_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  mischov
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Yeah, the above works for json input where that’s less of a concern, but for just arbitrary Elixir values you’d need to do more coercion.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="110944" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/insert-string-integer-map-list-in-a-jsonb-postgresql-column/19276/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-110944" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="110944"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #13"></div>
  </section>
</div>
    <div class="postbit" id="110946" data-post-id="110946">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Eiji" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Eiji/120/36743_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Eiji
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><a class="mention" href="/u/mischov" rel="nofollow">@mischov</a>: I think that this should work, but I did not fully tested it.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule Type.Json do
  alias Ecto.Type

  @behaviour Ecto.Type
  @moduledoc """
  To store values that might be any json value.

  Not intended as a general replacement for :map.
  """

  def type, do: :json

  def cast(value) when is_nil(value), do: {:ok, value}
  def cast(value) when is_boolean(value), do: {:ok, value}
  def cast(value) when is_binary(value), do: {:ok, value}
  def cast(value) when is_number(value), do: {:ok, value}
  def cast(value) when is_list(value), do: Type.cast({:array, __MODULE__}, value)
  def cast(value) when is_map(value), do: Type.cast({:map, __MODULE__}, value)
  def cast(_), do: :error

  def load(data), do: {:ok, data}

  def dump(value) when is_nil(value), do: {:ok, value}
  def dump(value) when is_boolean(value), do: {:ok, value}
  def dump(value) when is_binary(value), do: {:ok, value}
  def dump(value) when is_number(value), do: {:ok, value}
  def dump(value) when is_list(value), do: Type.dump({:array, __MODULE__}, value)
  def dump(value) when is_map(value), do: Type.dump({:map, __MODULE__}, value)
  def dump(_), do: :error
end
</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="110946" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/insert-string-integer-map-list-in-a-jsonb-postgresql-column/19276/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-110946" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="110946"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-solved cat-solved" title="Marked as solution"></div>
  </section>
</div>
    <div class="postbit" id="110948" data-post-id="110948">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="50kudos" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/50kudos/120/4435_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  50kudos
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I honestly think it’s not different on query (even without indexing) because it’s only slower on write (It will not re-parse once store). Of course its binary size could take more bytes per row (even if we name it just <code>d</code></p>
<p>I agree it’s not scalable, though I’m not sure that’s in term of space or time complexity.</p>
<p>Lets not going into old debate of <strong>best</strong> performance vs <strong>best</strong> development time or time to market or best maintainability etc. <img src="https://forum.elixirforum.com/images/emoji/apple/smile.png?v=15" title=":smile:" class="emoji" alt=":smile:" loading="lazy" width="20" height="20"></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="110948" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/insert-string-integer-map-list-in-a-jsonb-postgresql-column/19276/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-110948" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="110948"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #15"></div>
  </section>
</div>
    <div class="postbit" id="110960" data-post-id="110960">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Eiji" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Eiji/120/36743_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Eiji
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="50kudos" data-post="16" data-topic="19276">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/50kudos/48/4435_2.png" class="avatar"> 50kudos:</div>
<blockquote>
<p>I honestly think it’s not different on query (even without indexing) because it’s only slower on write (It will not re-parse once store). Of course its binary size could take more bytes per row (even if we name it just <code>d</code></p>
<p>I agree it’s not scalable, though I’m not sure that’s in term of space or time complexity.</p>
</blockquote>
</aside>
<p>Look, I’m not senior developer which would describe it properly. I believe this resource says enough:</p><aside class="onebox allowlistedgeneric" data-onebox-src="https://blog.plataformatec.com.br/2018/10/a-sneak-peek-at-ecto-3-0-performance-migrations-and-more/">
  <header class="source">
      <img src="https://forum.elixirforum.com/uploads/default/original/2X/9/960d9f8b092676c28aae5a89ec6f9d1c09a3a086.png" class="site-icon" alt="" data-dominant-color="155872" width="192" height="192">

      <a href="https://blog.plataformatec.com.br/2018/10/a-sneak-peek-at-ecto-3-0-performance-migrations-and-more/" target="_blank" rel="noopener nofollow ugc" title="05:41PM - 22 October 2018">Plataformatec Blog | Plataformatec's place to talk about Ruby, Ruby on Rails,... – 22 Oct 18</a>
  </header>

  <article class="onebox-body">
    

<h3><a href="https://blog.plataformatec.com.br/2018/10/a-sneak-peek-at-ecto-3-0-performance-migrations-and-more/" target="_blank" rel="noopener nofollow ugc">A sneak peek at Ecto 3.0: performance, migrations and more « Plataformatec Blog</a></h3>

  <p>Welcome to the "A sneak peek at Ecto 3.0" series: Breaking changes Query improvements part 1 Query improvements part 2 Performance, migrations and more (you are here!) We are back for one last round! This time we are going to cover improvements on...</p>


  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>

<aside class="quote no-group" data-username="50kudos" data-post="16" data-topic="19276">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/50kudos/48/4435_2.png" class="avatar"> 50kudos:</div>
<blockquote>
<p>Lets not going into old debate of <strong>best</strong> performance vs <strong>best</strong> development time or time to market or best maintainability etc. <img src="https://forum.elixirforum.com/images/emoji/apple/smile.png?v=15" title=":smile:" class="emoji" alt=":smile:" loading="lazy" width="20" height="20"></p>
</blockquote>
</aside>
<p>Generally we should think about it especially when others (like in above linked article) have do it and explained why. However I agree that it should not be a longer discussion - I just wanted to suggest better alternative solution.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="110960" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/insert-string-integer-map-list-in-a-jsonb-postgresql-column/19276/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-110960" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="110960"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>