Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id A5F9D632CE1 for ; Wed, 28 Apr 2010 16:19:51 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 92632-07 for ; Wed, 28 Apr 2010 19:19:43 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-qy0-f196.google.com (mail-qy0-f196.google.com [209.85.221.196]) by mail.postgresql.org (Postfix) with ESMTP id F2D896323B2 for ; Wed, 28 Apr 2010 16:19:42 -0300 (ADT) Received: by qyk34 with SMTP id 34so981476qyk.10 for ; Wed, 28 Apr 2010 12:19:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=lQSc8Cn9aosl+GF51ithWVh3NEX0jRtyk7quAUmIuR0=; b=FfYEmKQaXGja30d0+JMX47tUWaX+2DfiDJIOn47a6qYv4VGyFSQe6KDwWqx7R1JaAq SNlAynOAo+z1dau+NG6BdN/+ZHuIF9srYJ0t6C7L/jIFPxwEaT9OGGyeCii0jhSVOSqs NAEKQb3iWVQBLQCNKRV9DWMbzgdXw2ZsyatiE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=s5mlTYS3GfqBYdfl1sd40HBiMmCfHTWSEzWbbw4qBi93kMBfgFlZa5ctwH5neIm4R1 gICN7ihyPKrtkA42WojSSs/COE5p3QfM6StNofdcAtCVOWuD+P/hC0wl3SJapZlDVMVe zlWXm557WIIo5Lyt3JWnHbEPkJA/iyu7peSjA= MIME-Version: 1.0 Received: by 10.229.212.132 with SMTP id gs4mr4165734qcb.53.1272482380170; Wed, 28 Apr 2010 12:19:40 -0700 (PDT) Received: by 10.229.246.139 with HTTP; Wed, 28 Apr 2010 12:19:40 -0700 (PDT) In-Reply-To: <4BD86B65.3070006@magwerks.com> References: <4BD86B65.3070006@magwerks.com> Date: Wed, 28 Apr 2010 15:19:40 -0400 Message-ID: Subject: Re: Inserting Multiple Random Rows From: Gary Chambers To: Justin Graf Cc: pgsql-sql@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.801 tagged_above=-10 required=5 tests=BAYES_50=0.8, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201004/106 X-Sequence-Number: 34033 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 . =A0You 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-ro= w/ and the one that referred me to it at http://blog.rhodiumtoad.org.uk/2009/03/08/selecting-random-rows-from-a-tabl= e/ > 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! */