ActionView::Template::Error (PG::UndefinedFunction: ERROR: operator
does not exist: double precision ~~ unknown
2016-04-10T23:45:59.506005+00:00 app[web.1]: LINE 1: ... =
"trackers"."category_id" WHERE (categories.tag LIKE '1.%'...
this is the error i get when i try to run this line of code here
Tracker.group(:category_id).joins(:category).where('categories.tag LIKE ? AND user_id = ?', "#{tag.to_i}.%", current_user.id)
tag is of type float, and i typecast it to an integer in order to check for tags 1.1, 1.2, 1.3 etc
so in the example above I type cast tag with value 1.0 to be 1, so i can search for tags that are like 1.1, 1.2 etc
I am using postgres on heroku that gives this error. locally i use sqlite3 and it works just fine.
how can i overcome this?
Since you're in rails, sort out the dynamic-ness in rails first then send that to the ORM. The syntax you provided already accepts any parameters (eg: WHERE tag between ? and ?), so before you request the data from the ORM, sort out in rails the high and lows. The query is already setup for something to be dynamic.
Related
Since upgrading to Rails 5 I have a query that is not working. It is unable to get results from a table by its alias. The error is that "from" takes zero arguments now. The version of arel is 9.0, the version of Rails is 5.2.4.3
offers = Offer.arel_table
o2 = offers.alias("o2")
seen_offers = offers.from("offers as o2").project(o2[:merchant_id], o2[:display_name])
this is the error:
ArgumentError: wrong number of arguments (given 1, expected 0)
Arel::Table#from takes 0 arguments because it generates a SelectManager:
SelectManager.new(self)
What you are looking for is SelectManager#from and the issue is easily correctable (just switch the project and the from)
offers.project(o2[:merchant_id], o2[:display_name]).from(o2)
project will return a SelectManager and then from will simply change the source
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.
Look what arguments custom function is expecting and cast them.
like this: instead of SELECT custom_function(3, '{}', 'ipad') use SELECT custom_function(3, '{}'::json, 'ipad'::text) or SELECT custom_function(3, '{}'::text, 'ipad'::text) cos many types can go inside the quotes
I can upgrade php 5.2 in my server. I have to make this server work today (the vacation I have planned tomorrow is under question because of this error) with new testlink. I am stuck with following error i.e Paamayim nekudotayims.
What changes I should do to resolve it?
This link contains the file with the bug.
The Scope Resolution Operator (also called Paamayim Nekudotayim) or in simpler terms, the double colon, is a token that allows access to static, constant, and overridden properties or methods of a class.
SO may be in your codes you try to call static method or properties with wrong operator.
From Wikipedia:
In PHP, the scope resolution operator is also called Paamayim
Nekudotayim (Hebrew: פעמיים נקודתיים), which means “double colon” in
Hebrew.
The name "Paamayim Nekudotayim" was introduced in the
Israeli-developed Zend Engine 0.5 used in PHP 3. Although it has been
confusing to many developers who do not speak Hebrew, it is still
being used in PHP 5, as in this sample error message:
$ php -r :: Parse error: syntax error, unexpected
T_PAAMAYIM_NEKUDOTAYIM
As of PHP 5.4, error messages concerning the scope resolution operator
still include this name, but have clarified its meaning somewhat:
$ php -r :: Parse error: syntax error, unexpected '::'
(T_PAAMAYIM_NEKUDOTAYIM)
I'm running postgres 9 on mac lion... on a rails 3.2.3 web app.
I am querying a table for an entry called errors_rates_last_updated_at, which doesn't exist as of yet. So when I type the following in the rails console:
a = Settings.errors_rate_last_updated_at
I get a = 0000-01-01 00:00:00 -0800 . Fair enough.
Then when I query the Model with this date, with
Error.where('most_recent_notice_at > ?', a)
I get this error:
ActiveRecord::StatementInvalid: PG::Error: ERROR: date/time field value out of range: "0000-01-01 08:00:00.000000"
Could someone help me figure out what's going on? Thanks!
Rails is using a MySQL-ism that isn't valid on Pg. Zero timestamps are not permitted.
regress=# SELECT CAST('0000-01-01 08:00:00.000000' AS date);
ERROR: date/time field value out of range: "0000-01-01 08:00:00.000000"
LINE 1: SELECT CAST('0000-01-01 08:00:00.000000' AS date);
To understand more about how you're getting to that point you would need to enable query logging - either in PostgreSQL or rails - and find out what query caused the exception.
This morning I switched to postgresql and now my where selects dont work anymore.
What I am trying to do is super simple:
shirt_ids = "1,5,6" # String generated by javascript
Shirt.where("id in (?)", shirt_ids)
This gives me :
PG::Error: ERROR: invalid input syntax for integer: "1,5,6"
LINE 1: SELECT "shirts".* FROM "shirts" WHERE (id in ('1,5,6'))
This works though:
Shirt.where("id in (#{shirt_ids})")
But as everybody knows is unsafe.
Im using:
pg (0.13.2 x86-mingw32)
rails (3.2.2)
Postgresql database is the newest version, I installed it this morning.
Thank you for your help.
^
I believe Postgres is expecting an array, rather than a string for the IN function. If you convert your string to an array, it should work:
shirt_ids = "1,5,6"
Shirt.where('id in (?)', shirt_ids.split(','))
Also, you can do this, which looks a bit cleaner:
Shirt.where(:id => shirt_ids.split(','))