mercredi 5 août 2015

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:

D, [2015-08-05T23:10:06.029187 #1732] DEBUG -- :   Game Load (2.0ms)   SELECT field1, field2, field3
 FROM valuestable 
 WHERE ARRAY[field1] && (
 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] && (
          SELECT custom_function(3, '{}', 'ipad')
        );

We use Postgres 9.4.1/Redis/Rails/AWS.

The custom_function 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 .rb files in the db/migrate 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 user_functions.sql authored by one of my ex-colleagues in which the custom_function (from the above error) is referenced.

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.

Meta Information: I'm originally an iOS dev, trying to figure out some backend logic in the absence of a real backend person.

What I tried so far:

  • Making sure the version number of Postgres matches on server and local backend
  • Trying to use ActiveRecord::Base.connection.execute(IO.read("/path/to/user_functions.sql")) just before custom_function is first called.



Aucun commentaire:

Enregistrer un commentaire