2

I have sql table:

-- Table structure for rb_amazon_daily -- ---------------------------- DROP TABLE IF EXISTS `rb_amazon_daily`; CREATE TABLE `rb_amazon_daily` ( `id` int(11) NOT NULL AUTO_INCREMENT, `date` date DEFAULT NULL, `book_title` varchar(255) DEFAULT NULL, `marketplace` varchar(255) DEFAULT NULL, `amazon_kdp_avg_list_price` decimal(12,10) DEFAULT NULL, `amazon_kdp_royalty_type` varchar(255) DEFAULT NULL, `amazon_kdp_revenue_in_usd` decimal(13,13) DEFAULT NULL, `amazon_kdp_royalty_in_usd` decimal(13,13) DEFAULT NULL, `amazon_kdp_paid_downloads` int(11) DEFAULT NULL, `amazon_kdp_free_downloads` int(11) DEFAULT NULL, `amazon_ku_pages_read` int(11) DEFAULT NULL, `amazon_ku_revenue_in_usd` decimal(12,10) DEFAULT NULL, `create_space_revenue_in_usd` decimal(12,10) DEFAULT NULL, `create_space_royalty_in_usd` decimal(12,10) DEFAULT NULL, `create_space_paperbacks_sold` int(11) DEFAULT NULL, `daily_total_revenue` decimal(12,10) DEFAULT NULL, `daily_total_royalty` decimal(12,10) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=301 DEFAULT CHARSET=latin1; 

enter image description here And I have

class AmazonDaily < ActiveRecord::Base self.table_name = "rb_amazon_daily" end 

But then when I try to save somedata to database

#<AmazonDaily:0x007fffef743a00 id: nil, date: Sat, 16 Jul 2016, book_title: "Catalyst Moon: Incursion", marketplace: "Amazon.com", amazon_kdp_avg_list_price: 0.299e1, amazon_kdp_royalty_type: "70%", amazon_kdp_revenue_in_usd: 0.598e1, amazon_kdp_royalty_in_usd: 0.408e1, amazon_kdp_paid_downloads: 2, amazon_kdp_free_downloads: 0, amazon_ku_pages_read: 0, amazon_ku_revenue_in_usd: 0.0, create_space_revenue_in_usd: 0.0, create_space_royalty_in_usd: 0.0, create_space_paperbacks_sold: 0, daily_total_revenue: 0.598e1, daily_total_royalty: 0.408e1> 

I got an error: Error: Out of range value for column `

home/jonsdirewolf/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/mysql2-0.4.9/lib/mysql2/client.rb:120:in _query': Mysql2::Error: Out of range value for column 'amazon_kdp_revenue_in_usd' at row 1: INSERT INTOrb_amazon_daily (date,book_title,marketplace,amazon_kdp_avg_list_price, amazon_kdp_royalty_type,amazon_kdp_revenue_in_usd, amazon_kdp_royalty_in_usd,amazon_kdp_paid_downloads, amazon_kdp_free_downloads,amazon_ku_pages_read, amazon_ku_revenue_in_usd,create_space_revenue_in_usd, create_space_royalty_in_usd,create_space_paperbacks_sold, daily_total_revenue,daily_total_royalty`) VALUES ('2016-07-16', 'Catalyst Moon: Incursion', 'Amazon.com', 2.99, '70%', 5.98, 4.08, 2, 0, 0, 0.0, 0.0, 0.0, 0, 5.98, 4.08) (ActiveRecord::StatementInvalid)

` What do I do?

2
  • Could it have something to do with 'date' being length 0? Commented Sep 18, 2017 at 16:20
  • @user7733611 no, definetely - I tried to set length of date but navicat set it to zero when I saved table Commented Sep 18, 2017 at 16:22

1 Answer 1

1

The thing was in my decimal definition in sql table, I needed to alter my decimal columns likefo example:

 `amazon_kdp_revenue_in_usd` decimal(10,5) DEFAULT NULL, 

The declaration syntax for a DECIMAL column is DECIMAL(M,D). The ranges of values for the arguments in MySQL 5.7 are as follows:

M is the maximum number of digits (the precision). It has a range of 1 to 65.

D is the number of digits to the right of the decimal point (the scale). It has a range of 0 to 30 and must be no larger than M.

(this helped me: Warning#1264:out of range error in mysql)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.