pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Achilleas Mantzios <achill@matrix.gatewaynet.com>
To: pgsql-sql@postgresql.org
Subject: Re: [GENERAL] How to split a table?
Date: Tue, 17 Oct 2006 12:09:59 +0300
Message-ID: <200610171210.00269.achill@matrix.gatewaynet.com> (raw)
In-Reply-To: <20061017083418.GA3917@KanotixBox>
References: <c44bd2680610170039j3342e874ue78bc71a701f76e0@mail.gmail.com>
	<20061017083418.GA3917@KanotixBox>

Óôéò Ôñßôç 17 Ïêôþâñéïò 2006 11:34, ï/ç Andreas Kretschmer Ýãñáøå:
> Felix Zhang <felix.zhang.2005@gmail.com> schrieb:
> > Hi,
> >
> > I want to split a table to 2 small tables. The 1st one contains 60%
> > records which are randomly selected from the source table.
> > How to do it?
>
> Why do you want to do this?

In any case, you could write a program in perl and insert into the second 
table rows from the first table, using a techique of generarting random 
double precision numbers in a predetermined range (lets say 0 to 2^31-1), and 
then converting this number to your "range" like this:
let your number be r.
let your table's cardinality be N.
then let R=(N*r/(2^31))+1

select a source row from your table like:

select * from srctable order by pk offset <R>,
and then insert this row to your desttable.

>
>
> Andreas

-- 
Achilleas Mantzios



view thread (11+ messages)  latest in thread

Message-ID: <200610171210.00269.achill@matrix.gatewaynet.com>
Permalink:  ../200610171210.00269.achill@matrix.gatewaynet.com/
Also on:    postgresql.org/message-id/200610171210.00269.achill@matrix.gatewaynet.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: achill@matrix.gatewaynet.com
  Subject: Re: [GENERAL] How to split a table?
  In-Reply-To: <200610171210.00269.achill@matrix.gatewaynet.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