Skip site navigation (1) Skip section navigation (2)

How to creat tables using record ID in for loop

From: CHUNRIMACHUNRIMA <chunrima(at)hotmail(dot)com>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: How to creat tables using record ID in for loop
Date: 2008-08-06 18:52:34
Message-ID: BLU108-W46237DAA123B80A93E9DF4C87A0@phx.gbl (view raw or flat)
Thread:
Lists: pgsql-sql
1. I have created the first table and inserted records as below
CREATE TABLE mytest (
    staid varchar(20),
    kdesc  varchar(50)          -- description of gage station 
    )
    WITHOUT OIDS;







INSERT INTO mytest VALUES ('96784002', 'mylocation #1');
INSERT INTO mytest VALUES ('02385067', 'mylocation #2');
INSERT INTO mytest VALUES ('01734056', 'mylocation #3');
INSERT INTO mytest VALUES ('04784097', 'mylocation #4');
INSERT INTO mytest VALUES ('16784201', 'mylocation #5');


2. The records look like this.

SELECT * FROM mytest;







++++++++++++++++++++++++++
"96784002";"mylocation #1"
"02385067";"mylocation #2"
"01734056";"mylocation #3"
"04784097";"mylocation #4"
"16784201";"mylocation #5"
++++++++++++++++++++++++++


3. What I want to do is to create tables with staid from mytest table using for loop.But, since the name of tables should be in text format, I added a string 's' to staid. 
Thus, the name of table should be like this s96784002 because of 's' +'staid'.


+++Example+++





CREATE TABLE s06784000 (
    staid   varchar(50),
    val            real,          -- streamflow
    date            date)

WITHOUT OIDS;



4. I must create tables using for loop because I have millions of records. 
I appreciate your help in advance. 

Jae

 
_________________________________________________________________
강력해진 보안성, 아웃룩을 닮아 편리해진 기능들로 무장한 Windows Live Hotmail! 지금 로그인해 보세요!
http://www.hotmail.com

Responses

pgsql-sql by date

Next:From: Jorge MedinaDate: 2008-08-06 19:34:33
Subject: Re: more than 1000 connections
Previous:From: Scott MarloweDate: 2008-08-06 16:47:19
Subject: Re: more than 1000 connections

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group