title: How do you index a text column in postgreSQL?
body: <p>In MySQL Key Length is added as a type-modifier and placed in parenthesis colname(), one can provide it to CREATE INDEX like this,</p>
  
  <pre><code>CREATE INDEX foo_bar_idx ON foo ( bar(500) );
  </code></pre>
  
  <p><strong>scenario :</strong></p>
  
  <p><strong><em>Mysql custom db api function:</em></strong></p>
  
  <pre><code>def add_index(self, doctype, fields, index_name=None):
      """Creates an index with given fields if not already created.
      Index name will be `fieldname1_fieldname2_index`"""
      index_name = index_name or self.get_index_name(fields)
      table_name = 'tab' + doctype
      if not self.has_index(table_name, index_name):
          self.commit()
          self.sql("""ALTER TABLE `%s`
              ADD INDEX `%s`(%s)""" % (table_name, index_name, ", ".join(fields)))
  </code></pre>
  
  <p><strong><em>using the above for mysql as;</em></strong></p>
  
  <pre><code>hotelier.db.add_index("Item", ["route(500)"])
  </code></pre>
  
  <p><strong><em>postgresql custom db api function:</em></strong></p>
  
  <pre><code>def add_index(self, doctype, fields, index_name=None):
      """Creates an index with given fields if not already created.
      Index name will be `fieldname1_fieldname2_index`"""
      index_name = index_name or self.get_index_name(fields)
      table_name = 'tab' + doctype
  
      self.commit()
      self.sql("""CREATE INDEX IF NOT EXISTS "{}" ON `{}`("{}")""".format(index_name, table_name, '", "'.join(fields)))
  </code></pre>
  
  <p><strong>How to call the same thing in postgresql ?</strong> </p>
  
  <pre><code>hotelier.db.add_index("Item", ["route(500)"])
  </code></pre>