title: Postgresql instr that works with unicode
body: <p>I tried to do an instr in a postgresql query and then realized that it doesn't seem to have an instr function.</p>
  
  <p>Found this url <a href="http://www.postgresql.org/docs/9.1/static/plpgsql-porting.html#PLPGSQL-PORTING-APPENDIX" rel="nofollow">http://www.postgresql.org/docs/9.1/static/plpgsql-porting.html#PLPGSQL-PORTING-APPENDIX</a></p>
  
  <p>that shows how to implement instr in postgresql's plpgsql language.</p>
  
  <p>However it does not seem to work with unicode varchar columns, since I get the following error:</p>
  
  <pre><code>ERROR:  character with byte sequence 0xe4 0xb9 0xa6 in encoding "UTF8" has no equivalent in encoding "WIN1252"
  </code></pre>
  
  <p>even though I have used </p>
  
  <pre><code>SET client_encoding = 'UTF8';
  </code></pre>
  
  <p>on my client. Anyone know how to accomplish an instr with unicode?</p>
  
  <p>Found out that <code>position</code> is the postgresql equivalent to <code>instr</code>, but it gives the same error as above.</p>
  
  <p>This also didn't work:</p>
  
  <pre><code>select start from cnetd where substr(start, 6, 1) &lt;&gt; '/' and position('/' in convert(start, 'UTF8', 'LATIN1')) &gt; 0 limit 90;
  
  ERROR:  function convert(character varying, unknown, unknown) does not exist
  LINE 1: ...re substr(start, 6, 1) &lt;&gt; '/' and position('/' in convert(st...
                                                               ^
  HINT:  No function matches the given name and argument types. You might need to
  add explicit type casts.
  </code></pre>