title: Postgres: Add full-text search on existing varchar column?
body: <p>I have an existing Postgres 9.3 database with a table with a varchar column.</p>
  
  <pre><code>        Table "public.frontend_chemical"
    Column   |          Type          | Modifiers
  -----------+------------------------+-----------
   bnf_code  | character varying(9)   | not null
   chem_name | character varying(200) | not null
  </code></pre>
  
  <p>I would like to run full-text search on the <code>chem_name</code> column. </p>
  
  <p>I have been reading <a href="http://dlo.me/archives/2014/09/01/postgresql-fts/" rel="noreferrer">this article</a>, which suggests the steps are as follows:</p>
  
  <ol>
  <li>Add a new <code>tsvector</code> column: <code>ALTER TABLE frontend_chemical ADD COLUMN fts_document tsvector;</code></li>
  <li>Create a function to map the <code>chem_name</code> column to the document, and a trigger to keep it updated.</li>
  <li>Create a GIN index on the column: <code>CREATE INDEX chem_fts_index ON frontend_chemical USING gin(fts_document)</code>;</li>
  </ol>
  
  <p>Then I should be able to run full-text search queries like: <code>SELECT COUNT(*) FROM frontend_chemical WHERE fts_document @@ 'statin';</code>. </p>
  
  <p>Firstly, is that general process correct? </p>
  
  <p>Secondly, how do I map all the existing entries in the <code>chem_name</code> column to the <code>fts_document</code> column? The example in the article seems to only update the <code>document</code> column when the <code>chem_name</code> column is updated, whereas I have a large existing database.</p>