Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8489007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:42:21+00:00 2026-06-10T21:42:21+00:00

In Ruby, I have a test that’s a subclass of ActiveSupport::TestCase and access a

  • 0

In Ruby, I have a test that’s a subclass of ActiveSupport::TestCase and access a table through an ActiveRecord subclass in a Postgres (actually Greenplum) database. For a particular test I need to populate the table with on the order of a million rows, but I don’t really care what’s in there. I could do something like

for i in 1...1000000 do
  MyTable.create(:column1 => 'value', :column2 => 'value')
end

but this will take a long time to run. I could make it a little faster by wrapping it in a transaction so that create won’t create a new one every time, but that will only save so much time.

Is there some nice way to do this so that I don’t have to execute a lot of inserts of bogus values into the table?

(Note: stubbing things out to try to pretend that the table contains a million records won’t work because I later on need to interact with the actual rows; for this particular test I just don’t care what they are)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T21:42:23+00:00Added an answer on June 10, 2026 at 9:42 pm

    Run all that in a simple query like:

    INSERT INTO mytable (col1, col2) 
    SELECT 'value1', 'value2' 
    FROM generate_series(1,1000000);
    

    This should populate database pretty fast. It takes 2 seconds my laptop.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

so i have ruby script that simply writes to a test.txt file with hello
I have a test environment that uses Ruby to drive a server over an
I have Ruby script that creates a proxy so that I can make HTTP
Suppose I have a class in Ruby: class Test def method(arg1, arg2) return arg1+arg2
I have one problem with the command rake test that I don't know how
I have a 2-dimensional array in Ruby that I want to produce a working
I have a Ruby program that generates files that contain a Module definition :
I have test app written on ruby, using Sinatra+Sequel. config.ru: require './main' run Sinatra::Application
I have a Page scaffold that I created through rails generate scaffold. I ran
I have a step definition in my cucumber test suite that authenticates the user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.