Re: [NOVICE] How to split a table? - Mailing list pgsql-general

From Obe, Regina
Subject Re: [NOVICE] How to split a table?
Date
Msg-id 53F9CF533E1AA14EA1F8C5C08ABC08D201044B3D@ZDND.DND.boston.cob
Whole thread Raw
List pgsql-general
I would do
 
select * into mynewtable from myoldtable ORDER by random() LIMIT 15000
 
where 15000 in this case is <your table row count>*.6
 
If you want to create another table with 40% of the remaining data then something like
 
select * into mynewtable2 from myoldtable where myoldtable.primarykey NOT IN(select primarykey from mynewtable)
]
In this case primarykey you would replace with the primary key field of your table.


From: pgsql-novice-owner@postgresql.org [mailto:pgsql-novice-owner@postgresql.org] On Behalf Of Felix Zhang
Sent: Tuesday, October 17, 2006 3:39 AM
To: pgsql-sql@postgresql.org; pgsql-general@postgresql.org; pgsql-novice@postgresql.org
Subject: [NOVICE] How to split a table?

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?
 
Regards,
Felix




The substance of this message, including any attachments, may be
confidential, legally
privileged and/or exempt from disclosure pursuant to Massachusetts
law. It is intended
solely for the addressee. If you received this in error, please
contact the sender and
delete the material from any computer.

pgsql-general by date:

Previous
From: Shane Ambler
Date:
Subject: Re: Any documatation about porting from Oracle to PostgreSQL
Next
From: Stefan Sassenberg
Date:
Subject: ERRORDATA_STACK_SIZE exceeded