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

  • SEARCH
  • Home
  • 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 5991877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:27:05+00:00 2026-05-22T23:27:05+00:00

I have to generate about a million random trips between about 40K destinations. Each

  • 0

I have to generate about a million random trips between about 40K destinations. Each destination has it’s own weight (total_probability), the more it is, the more trips should start or end in this place.

Either the trips should be generated randomly, but destinations (start and end points) should be weighted by probability, or it’s possible to just pre-calculate an exact number of trips (divide each weight by the sum of weights, multiply by 1M and round to integers).

Problem is how to make it in PostgreSQL without generating the 40K*40K table with all destinations pairs.

          Table "public.dests"
   Column          |       Type       | Modifiers 
-------------------+------------------+-----------
 id                | integer          | 
 total_probability | double precision | 

          Table "public.trips"
   Column   |       Type       | Modifiers 
------------+------------------+-----------
 from_id    | integer          | 
 to_id      | integer          | 
 trips_num  | integer          | 
 ...
 some other metrics...

primary key for trips is (from_id, to_id)
Should I generate a table with 1M records and then update it iteratively, or a for loop with 1M inserts will be fast enough? I work on a 2-core lightweight laptop.

P.S. I gave up and did this in Python. To perform a set of queries and the transformation in Python, I’ll run SQL scripts from Python rather than from a shell script. Thanks for suggestions!

  • 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-05-22T23:27:06+00:00Added an answer on May 22, 2026 at 11:27 pm

    In 9.1, you can use TRIGGERs on VIEWs, which effectively let you create materialized views (albeit manually). I think your first run may be expensive, but using a loop is probably the way to go, but then after that, I’d use a series of TRIGGERs to maintain the data in a table.

    At the end of the day you need to decide whether or not you want to calculate the results for every query, or you memoize the result via a materialized view.

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

Sidebar

Related Questions

I have to generate two random sets of matrices Each containing 3 digit numbers
I have a program where I generate bitstreams, of about 80 to 150 bits
I have a old website that generate its own RSS everytime a new post
I have a process that's going to initially generate 3-4 million PDF files, and
I have a denormalized table product with about 6 million rows (~ 2GB) mainly
Backstory: In the past users have complained about how long it takes to generate
I have a PHP-generated page which is displaying some data about a set of
For testing purposes I have to generate a file of a certain size (to
I have a new app I'll be working on where I have to generate
i'm want to have a repeater generate a bunch of checkboxes, e.g.: <tr><td><input type=checkbox

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.