title: mySQL to PostgreSQL concat first name and last name for name search (Ruby on Rails)
body: <p>Hey I'm trying to figure out how to convert a statement that works in mySQL into PostgreSQL and curious if anybody knows the solution.</p>
  
  <p>Here is the statement that works in mySQL:</p>
  
  <pre><code>def self.by_name(keywords)
      if keywords
          find(:all, :conditions =&gt; ["concat(first_name," ",last_name) like?", "%#{keywords}%"])
  
      end
    end
  </code></pre>
  
  <p>Here is the statement that I found on <a href="http://archives.postgresql.org/pgsql-sql/2000-07/msg00294.php" rel="nofollow">this site</a> that basically had a similar problem, but it doesn't work for me, as in, if I do a search like Contact.by_name("Bobby"), there are no results.</p>
  
  <pre><code>def self.by_name(keywords)
      if keywords
          find(:all, :conditions =&gt; ["textcat(textcat(first_name,text ' '),last_name) like?", "%#{keywords}%"])
      end
    end
  </code></pre>
  
  <p>The idea is that I could search for "Bobby", "Fishcer", or "Bobby Fischer" and it would match anybody with either that first name, last name, or both first and last name. Thanks! </p>