title: Postgres - casting text to ltree
body: <p>Im new to postgres and am looking to utilize ltree for a hierarchal data structure. </p>
  
  <p>I have the both the data and the ltree structure (ie domain.class.sublass) in varchar columns, and need to cast the ltree structure into another column with the proper ltree data type. </p>
  
  <p>Ive identified text2ltree as the best way to likely manage this but havent made much headway even after reading the ltree documentation  and ltree function information</p>
  
  <ul>
  <li><a href="https://www.postgresql.org/docs/9.1/static/ltree.html" rel="nofollow noreferrer">https://www.postgresql.org/docs/9.1/static/ltree.html</a></li>
  <li><a href="https://www.postgresql.org/docs/9.4/static/functions-formatting.html" rel="nofollow noreferrer">https://www.postgresql.org/docs/9.4/static/functions-formatting.html</a></li>
  </ul>
  
  <p>Ive tried many combinations of the below </p>
  
  <pre><code> alter table codes
  alter column joinedclassname type ltree using text2ltree(joinedclassname);
  </code></pre>
  
  <p>but receive the following error:</p>
  
  <blockquote>
  <pre><code>ERROR:  syntax error at position 26
  ********** Error **********
  
  ERROR: syntax error at position 26
  SQL state: 42601
  </code></pre>
  </blockquote>
  
  <p>Ive also tried the following and recieved the same error:</p>
  
  <blockquote>
  <pre><code>alter table codes
  alter column joinedclassname type ltree using joinedclassname::ltree;
  </code></pre>
  </blockquote>
  
  <p>How do I cast a ltree hiearchary from a varchar column to a column with a ltree data type? </p>
  
  <p>Thanks!</p>