pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jorge Godoy <jgodoy@gmail.com>
To: Gregory S. Williamson <gsw@globexplorer.com>
Cc: A. Kretschmer <andreas.kretschmer@schollglas.com>
Cc: pgsql-sql@postgresql.org
Cc: pgsql-novice@postgresql.org
Subject: Re: [SQL] [GENERAL] How to split a table?
Date: Tue, 17 Oct 2006 08:51:49 -0200
Message-ID: <87pscrqko3.fsf@gmail.com> (raw)
In-Reply-To: <71E37EF6B7DCC1499CEA0316A256832802B3E737@loki.wc.globexplorer.net>
References: <c44bd2680610170039j3342e874ue78bc71a701f76e0@mail.gmail.com>
	<20061017083418.GA3917@KanotixBox>
	<71E37EF6B7DCC1499CEA0316A256832802B3E735@loki.wc.globexplorer.net>
	<20061017091237.GA19268@a-kretschmer.de>
	<71E37EF6B7DCC1499CEA0316A256832802B3E737@loki.wc.globexplorer.net>

"Gregory S. Williamson" <gsw@globexplorer.com> writes:

> A crude approach would be to add a column to the original table; then update
> that based on the rand() call:
>
> update foo set i_am_a_60 = 1 where (rand() <= 0.60);
> create table foo_60 as select * from foo where i_am_a_60 = 1;
> create table foo_40 as select * from foo where i_am_a_60 <> 1;
>
> The CASE condition might be usable as well but I haven't puzzled it out ...

If he's asking that 60% of the contents of the original table be randomly
selected this won't work.  He'll have to count how many rows the original
table has, then loop randomly selecting rows until he has reached 60% of that
total.  Otherwise he might end up with something completely different from
what he wants.

On the other hand if he wants rows whose randomness factor at the time they
were looked at was bigger than 0.6 then he can use that rand() trick.

-- 
Jorge Godoy      <jgodoy@gmail.com>



view thread (11+ messages)  latest in thread

Message-ID: <87pscrqko3.fsf@gmail.com>
Permalink:  ../87pscrqko3.fsf@gmail.com/
Also on:    postgresql.org/message-id/87pscrqko3.fsf@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: jgodoy@gmail.com, gsw@globexplorer.com, andreas.kretschmer@schollglas.com, pgsql-novice@postgresql.org
  Subject: Re: [SQL] [GENERAL] How to split a table?
  In-Reply-To: <87pscrqko3.fsf@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox