title: postgres comparing varying character with array from string_to_array
body: <p>I'm having problems comparing Postgres types, and would be grateful for some help. I am extracting valid document types from a configuration table that holds a tilda-separated string, as follows:</p>
  
  <pre><code>SELECT string_to_array(value,'|') as document_kinds
    FROM company_configs
    WHERE option = 'document_kinds'
  </code></pre>
  
  <p>this gives me an array of values, so</p>
  
  <p>'doc1|doc2|doc3' becomes {doc1,doc2,doc3}</p>
  
  <p>Next I need to select the documents for a given person which match my document types:</p>
  
  <pre><code>SELECT * FROM people
    JOIN documents ON ...
    WHERE kind IN
     (SELECT string_to_array(value,'|') as document_kinds
      FROM company_configs
      WHERE option = 'document_kinds')
  </code></pre>
  
  <p>the documents.kind column is 'character varying'
  my understanding is that string_to_array is producing an array of text values 'text[]'</p>
  
  <p>This query produces the error 'ERROR:  operator does not exist: character varying = text[]'</p>
  
  <p>If I cast 'kind' into text, with </p>
  
  <pre><code>SELECT * FROM people
   JOIN documents ON ...
   WHERE kind::text IN
    (SELECT string_to_array(value,'|') as visa_document_kinds FROM languages_united.company_configs WHERE option = 'visa_document_kinds')
  </code></pre>
  
  <p>I get the error 'ERROR:  operator does not exist: text = text[]'</p>
  
  <p>I'm not sure how to compare the two, and would be grateful for any advice.</p>
  
  <p>Thanks in advance
  Dan</p>
  
  <p>Postgres 9.4.1</p>