Re: Inserting Multiple Random Rows

From: Gary Chambers <gwchamb(at)gmail(dot)com>
To: Justin Graf <justin(at)magwerks(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Inserting Multiple Random Rows
Date: 2010-04-28 19:19:40
Message-ID: w2q302670f21004281219ue31d0e61xe3a76d0e2a49b5be@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Justin,

Thanks for the reply!

> you need to generate a series of random numbers then select each record
> one at a time out of cities table .  You will have to write a plsql
> function to do this As any join will cause the result to be ordered.

After modifying my search terms at Google, I've discovered that I'm
not alone in this endeavor. There are a couple of informative
articles, the most beneficial of which is written by depesz at
http://www.depesz.com/index.php/2007/09/16/my-thoughts-on-getting-random-row/
and the one that referred me to it at
http://blog.rhodiumtoad.org.uk/2009/03/08/selecting-random-rows-from-a-table/

> Here is example of pl-sql procedure that inserts records randomly into a
> table from a another table.

I could have been done with this in pretty short order if I had just
continued with writing a quick PL/pgSQL function to do it. It's all
Quassnoi's fault that I abandoned my original plan and tried to solve
the problem with a query. After all, I need to learn to think in sets
and get out of the procedural mindset, but I still haven't heard the
click! :)

Thanks for the suggestion in your follow-up e-mail. I'll post the
solution upon discovering it.

-- Gary Chambers

/* Nothing fancy and nothing Microsoft! */

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Gary Chambers 2010-04-28 20:04:11 Re: Inserting Multiple Random Rows
Previous Message Justin Graf 2010-04-28 19:03:34 Re: Inserting Multiple Random Rows