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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Sorry to necro an old thread, but just wanted to pop in here and add the above was very helpful, however I got a <code>malformed array literal</code> error from PSQL when trying to use the method above for specifying an empty array <code>[]</code>.</p>
<p>Resolution that worked for me, in case anyone else is struggling with the same issue and winds up here, was to use <code>array[]::varchar[]</code> instead of <code>[]</code></p>
<p>Didn’t work:<br>
<code>execute("ALTER TABLE table_name ALTER COLUMN column_name type varchar(255)[] using string_to_array(column_name, ','), ALTER column_name SET default '[]' ")</code></p>
<p>Worked:<br>
<code>execute("ALTER TABLE table_name ALTER COLUMN column_name type varchar(255)[] using string_to_array(column_name, ','), ALTER column_name SET default array[]::varchar[]")</code></p>
<p>My SQL/PSQL skills are very poor however, so maybe I’m just missing something.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="268680" data-batch-url="/posts/batch_likers">
                        1
                      </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/ecto-changeset-modify-column-type-from-string-to-array-string/32209/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-268680" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="268680"
                     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="268684" data-post-id="268684">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>What you have is fine but you should be able to do the array literal as well.  The problem is that <code>'[]'</code> is not the syntax for array literals, <code>'{}'</code> is.  A quick demonstration…</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">127.0.0.1(from musebms).msmcp_dev.scb.5432 [Thu Nov 17 02:56:13 PM PST 2022]
&gt; create table scb_test (id bigint primary key generated always as identity, test_col text);
CREATE TABLE
Time: 15.896 ms
127.0.0.1(from musebms).msmcp_dev.scb.5432 [Fri Nov 18 09:52:24 AM PST 2022]
&gt; alter table scb_test alter column test_col type text[] using string_to_array(test_col, ',');
ALTER TABLE
Time: 51.545 ms
127.0.0.1(from musebms).msmcp_dev.scb.5432 [Fri Nov 18 09:54:26 AM PST 2022]
&gt; alter table scb_test alter column test_col set default '{}';
ALTER TABLE
Time: 2.799 ms

</code></pre>
<p>So the following should work (though I have not tested)…</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">execute("""
  ALTER TABLE table_name ALTER COLUMN column_name type varchar(255)[] 
    USING string_to_array(column_name, ','), ALTER column_name SET DEFAULT '{}' 
  """)
</code></pre>
<p>Admittedly I do prefer to specify the type with the literal syntax like: <code>'{}'::varchar(255)[]</code></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="268684" data-batch-url="/posts/batch_likers">
                        2
                      </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/ecto-changeset-modify-column-type-from-string-to-array-string/32209/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-268684" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="268684"
                     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="268687" data-post-id="268687">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I figured it was something basic I didn’t understand – thanks!</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="268687" 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/ecto-changeset-modify-column-type-from-string-to-array-string/32209/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-268687" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="268687"
                     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>