Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I need to do a multiple insertion in the database.It shows me an error all the time

Single insertion works perfect:

CONN = ActiveRecord::Base.connection

irb(main):271:0> inserts.push'(1,2,3,4,5,6)'
=> ["(1,2,3,4,5,6)"]

sql="INSERT INTO signals_rmas (groupsnorm_id, arraydb_id, probeset_id,signal,updated_at,created_at) VALUES #{inserts.join(", ")}"

irb(main):276:0> CONN.execute sql
   (32.3ms)  INSERT INTO signals_rmas (groupsnorm_id, arraydb_id, probeset_id,signal,updated_at,created_at) VALUES (1,2,3,4,5,6)
=> []

Multiple insertions do not work at all:

irb(main):272:0> inserts.push'(7,8,9,10,11,12)'
=> ["(1,2,3,4,5,6)", "(7,8,9,10,11,12)"]

irb(main):278:0>sql="INSERT INTO signals_rmas (groupsnorm_id, arraydb_id, probeset_id,signal,updated_at,created_at) VALUES #{inserts.join(", ")}"
=> "INSERT INTO signals_rmas (groupsnorm_id, arraydb_id, probeset_id,signal,updated_at,created_at) VALUES (1,2,3,4,5,6), (7,8,9,10,11,12)"

irb(main):279:0> CONN.execute sql
   (0.4ms)  INSERT INTO signals_rmas (groupsnorm_id, arraydb_id, probeset_id,signal,updated_at,created_at) VALUES (1,2,3,4,5,6), (7,8,9,10,11,12)
ActiveRecord::StatementInvalid: SQLite3::SQLException: near ",": syntax error: INSERT INTO signals_rmas (groupsnorm_id, arraydb_id, probeset_id,signal,updated_at,created_at) VALUES (1,2,3,4,5,6), (7,8,9,10,11,12)

What is the problem? How can I insert multiple records as a time in sql?(create record) Thanks in advance

share|improve this question

1 Answer

up vote 0 down vote accepted

It looks like SQLite doesn't support inserting multiple records.

http://stackoverflow.com/a/5009740/199712

share|improve this answer
 
yep. It is still limited up to 500 records. –  Katja May 21 at 19:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.