Skip to content

ActiveRecord::StatementInvalid: PG::SyntaxError: ERROR: VALUES lists must all be the same length #12

@sergeykish

Description

@sergeykish

Once run bulk_insert with non constant attributes count

records = [
  { :name => "Foo", :age => 30 },
  { :name => "Bar" }
]
expect {SampleRecord.bulk_insert(records)}.to change{SampleRecord.count}.by(records.size)

It fails

 ActiveRecord::StatementInvalid:
   SQLite3::SQLException: all VALUES must have the same number of terms:       INSERT INTO "sample_records"
           (name, age, created_at, updated_at)
         VALUES
           ('Foo', 30, '2017-05-04 12:44:57.825195', '2017-05-04 12:44:57.825195'),('Bar', '2017-05-04 12:44:57.825351', '2017-05-04 12:44:57.825351')
 # ./lib/active_record_bulk_insert.rb:40:in `bulk_insert'
 # ./spec/sample_record_spec.rb:24:in `block (4 levels) in <top (required)>'
 # ./spec/sample_record_spec.rb:24:in `block (3 levels) in <top (required)>'

As you can see it does not fill gap

INSERT INTO "sample_records" 
  (name, age, created_at, updated_at)
VALUES                       
  ('Foo', 30, '2017-05-04 12:44:57.825195', '2017-05-04 12:44:57.825195'),
  ('Bar',     '2017-05-04 12:44:57.825351', '2017-05-04 12:44:57.825351')
          ^^^ here

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions