Postgres Date/Time Field value out of range - ruby-on-rails

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.

Related

postgres - operator does not exist: double precision ~~ unknown

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.

solr 5.3.1 is giving org.apache.solr.common.SolrException: ERROR: [doc=model id] Error adding field

I was working on rails app and I want to use solr as search engine so I installed latest version of solr and while I was trying to index I was getting this error:
org.apache.solr.common.SolrException: ERROR: [doc=User 6] Error adding field 'published_at_d'='2012-07-13T20:58:58Z' msg=For input string: "2012-07-13T20:58:58Z"
at org.apache.solr.update.DocumentBuilder.toDocument(DocumentBuilder.java:176)
Caused by: java.lang.NumberFormatException: For input string: "2012-07-13T20:58:58Z"**
Please suggest possible solution to resolve it. I checked several sites and tried editing my solrconfig.xml file with date formats still it is not working.
Check your schema: the
published_at_d
field should have TrieDate as type. Here, it seems it has been defined as TrieLong or some other numeric type and that cause the NaN failure

Sunspot Solr Reindexing failing due to illegal characters

I'm having an issue where Solr is failing to reindex my site, due to the following error from my production log:
bundle exec rake sunspot:solr:reindex
rake aborted!
RSolr::Error::Http: RSolr::Error::Http - 400 Bad Request
Error: Illegal character ((CTRL-CHAR, code 12))
at [row,col {unknown-source}]: [155,1]
I am not sure where this 'illegal character' is being generated from, nor where to find this. I more than appreciate everyone's help, as it is causing a 500 server error on my app right now. Thank you, and let me know if more information is needed.
(Rails 3.2)
(Rsolr 1.0.10)
Usually this is caused by bad data in your database. If you're using MySQL you can find any instances of control character 12 with a query like this:
SELECT * FROM table WHERE col REGEXP CHAR(12);
Then you can remove the character from the content of any matched rows & proceed to reindex.
You could also do something like this to remove the control characters:
UPDATE table SET col=REPLACE(col, CHAR(12), '') WHERE col REGEXP CHAR(12);

Quartz.Net error on common logging.

I am getting the following error:
2013-11-14 11:57:33,994 [TestScheduler_QuartzSchedulerThread] ERROR Common.Loggi
ng.Factory.AbstractLogger.Error(:0) - An error occurred while scanning for the n
ext trigger to fire.
Quartz.JobPersistenceException: Couldn't acquire next trigger: Cannot insert the
value NULL into column 'SCHED_TIME', table 'quartz.dbo.QRTZ_FIRED_TRIGGERS'; co
lumn does not allow nulls. INSERT fails.
The statement has been terminated. ---> System.Data.SqlClient.SqlException: Cann
ot insert the value NULL into column 'SCHED_TIME', table 'quartz.dbo.QRTZ_FIRED_
TRIGGERS'; column does not allow nulls. INSERT fails.
The statement has been terminated.
I am using the example from HERE and I think I need to understand how jobs work with ADO.Net Jobstore better. My code works perfectly with RAMJobStore. Is there something else I have to do to get ADO to scan for triggers?
Turns out when I looked closer at the errors it was referencing the older version of Quartz.net.

Postgresql WHERE clause adds '' around?

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(','))

Resources