title: Postgres to_tsvector VS ::tsvector
body: <p>I don't really understand the difference between <code>to_tsvector</code> and <code>::tsvector</code> in Postgres. I read the documentation on <code>to_tsvector</code><a href="http://www.postgresql.org/docs/9.1/static/functions-textsearch.html" rel="noreferrer">here</a>, but there doesn't seem to be any documentation for the other, <code>::tsvector</code> - that's a bit problematic. It is mentioned <a href="http://www.postgresql.org/docs/8.3/static/datatype-textsearch.html" rel="noreferrer">here</a>, but it says something about <em>normalizing</em> before querying, and normalization is done through <code>to_tsvector</code>.</p>
  
  <p>I created <a href="http://sqlfiddle.com/#!15/3a14b/10" rel="noreferrer">this SQL Fiddle</a> to demonstrate the two; here is the code if you don't want to navigate away:</p>
  
  <p><strong>DDL</strong>:</p>
  
  <pre><code>CREATE TABLE text (
    text_id serial PRIMARY KEY,
    source_text text NOT NULL,
    destination_text text NOT NULL
  );
  </code></pre>
  
  <p>and the <strong>SQL</strong>:</p>
  
  <pre><code>-- Throw some stuff in there
  INSERT INTO text (source_text, destination_text) VALUES
  ('Hello', 'Hello Result'),
  ('With Comma, Query', 'WithComma, Result');
  
  -- Forced to use punctuation in the query to match what is in the vector
  SELECT T.source_text, T.destination_text
  FROM   text T
  WHERE  LOWER(T.source_text)::tsvector @@ LOWER('Hello')::tsquery;
  
  -- Vector free of punctuation, don't include it in the query
  SELECT T.source_text, T.destination_text
  FROM   text T
  WHERE  to_tsvector(LOWER(T.source_text)) @@ LOWER('Comma')::tsquery;
  
  SELECT ts_debug('english', 'Something without a comma');
  
  SELECT ts_debug('english', 'Something, with a comma');
  </code></pre>
  
  <p>It seems to me that <code>to_tsvector</code> will take the text, strip it of punctuation and return the vector. On the other hand, <code>::tsvector</code> seems to include the punctuation in the vector, resulting in a need to use the same punctuation in the query.</p>
  
  <p>What are the practical differences between the two? Is one generally preferred over the other? In what situations is each preferred?</p>