Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is no implicit cast from <code>varchar</code> to <code>varchar[]</code> in Postgres. You must indicate how to perform the conversion of the types. You should do it in <code>USING expression</code> clause (see <a href="http://www.postgresql.org/docs/9.2/static/sql-altertable.html" rel="noreferrer">ALTER TABLE</a> in the documentation). In that case you have to drop and recreate the default value of the column, as it is explained in the documentation:</p> <blockquote> <p>The USING option of SET DATA TYPE can actually specify any expression involving the old values of the row; that is, it can refer to other columns as well as the one being converted. This allows very general conversions to be done with the SET DATA TYPE syntax. Because of this flexibility, the USING expression is not applied to the column's default value (if any); the result might not be a constant expression as required for a default. This means that when there is no implicit or assignment cast from old to new type, SET DATA TYPE might fail to convert the default even though a USING clause is supplied. In such cases, drop the default with DROP DEFAULT, perform the ALTER TYPE, and then use SET DEFAULT to add a suitable new default.</p> </blockquote> <pre><code>alter table containers alter products drop default; alter table containers alter products type text[] using array[products]; alter table containers alter products set default '{}'; </code></pre> <p>The three operations can be done in one statement:</p> <pre><code>alter table containers alter products drop default, alter products type text[] using array[products], alter products set default '{}'; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload