X-Original-To: pgsql-general-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id A26169FA38F for ; Tue, 13 Jun 2006 20:09:24 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 43194-05 for ; Tue, 13 Jun 2006 20:09:19 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id CF8969FA1A8 for ; Tue, 13 Jun 2006 20:09:19 -0300 (ADT) Received: by noel.decibel.org (Postfix, from userid 1001) id 9AB6656435; Tue, 13 Jun 2006 18:09:18 -0500 (CDT) Received: (hashcash-sendmail, from uid 1001); Tue, 13 Jun 2006 18:09:17 -0500 Date: Tue, 13 Jun 2006 18:09:17 -0500 From: "Jim C. Nasby" To: Tom Lane Cc: Milen Kulev , pgsql-general@postgresql.org Subject: Re: Partitioning... Message-ID: <20060613230917.GQ34196@pervasive.com> References: <007701c68e6f$0e992770$0a00a8c0@trivadis.com> <13439.1150153086@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <13439.1150153086@sss.pgh.pa.us> X-Operating-System: FreeBSD 6.0-RELEASE-p4 amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Hashcash: 1:20:060613:tgl@sss.pgh.pa.us::j/lxxotYo1AZFZxD:00000000000000000000 0000000000000000000000001WhF X-Hashcash: 1:20:060613:makulev@gmx.net::Ac0U0ic6p+1HZL8s:004LsW X-Hashcash: 1:20:060613:pgsql-general@postgresql.org::uKd+72Foe8L5NnWn:000000000 0000000000000000000000000rAm X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/537 X-Sequence-Number: 96909 On Mon, Jun 12, 2006 at 06:58:06PM -0400, Tom Lane wrote: > "Milen Kulev" writes: > > What is wrong with random() ? > > Not guaranteed to be stable across the multiple evaluations that the > rule will perform ... remember a rule is a macro and has the usual > multiple-evaluation gotchas in the face of volatile arguments. I believe a safe alternative would be... INSERT INTO ... SELECT * FROM (SELECT random()*20 FROM ...) ; You might need to add an ORDER BY to the subquery to ensure PostgreSQL doesn't pull it into the main query. -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461