title: ActiveRecord::StatementInvalid (PG::UndefinedFunction: ERROR: function <function_name>(integer, unknown, unknown) does not exist
body: <p>I'm in the process of setting up the backend environment for a mobile app on my local machine and a Postgres function call within a Ruby model errors out the request. Here's the log:</p>
  
  <pre><code>D, [2015-08-05T23:10:06.029187 #1732] DEBUG -- :   Game Load (2.0ms)   SELECT field1, field2, field3
   FROM valuestable 
   WHERE ARRAY[field1] &amp;&amp; (
   SELECT custom_function(3, '{}', 'ipad')
   );
  
  E, [2015-08-05T23:10:06.029262 #1732] ERROR -- : PG::UndefinedFunction: ERROR:  function custom_function(integer, unknown, unknown) does not exist
  LINE 4:           SELECT custom_function(3, '{}', 'ipad')
                           ^
  HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
            SELECT field1, field2, field3
            FROM gamestable 
            WHERE ARRAY[field1] &amp;&amp; (
            SELECT custom_function(3, '{}', 'ipad')
          );
  </code></pre>
  
  <p>We use Postgres 9.4.1/Redis/Rails/AWS. </p>
  
  <p>The <code>custom_function</code> in the above sql query is defined in a class that got auto created during a migration. I see it in one of the time-stamped <code>.rb</code> files in the <code>db/migrate</code> folder of the said ruby app. However, I do not know how to "include/import" that into my model so this error can be prevented. I have an sql file called <code>user_functions.sql</code> authored by one of my ex-colleagues in which the <code>custom_function</code> (from the above error) is referenced. </p>
  
  <p>Also, another interesting point is this application runs perfectly on both Staging and Production. It's only on the local machine that it doesn't work. I have no idea if this is some kind of a one-time setup on the backend run directly on AWS or if it's simply a step I'm missing while setting up my local backend.</p>
  
  <p>Meta Information: I'm originally an iOS dev, trying to figure out some backend logic in the absence of a real backend person. </p>
  
  <p>What I tried so far:</p>
  
  <ul>
  <li>Making sure the version number of Postgres matches on server and local backend</li>
  <li>Trying to use ActiveRecord::Base.connection.execute(IO.read("/path/to/user_functions.sql")) just before <code>custom_function</code> is first called.</li>
  </ul>