Postgresql Copy
COPY
=====
Transfer the data from student table operating system as flatfile
www.sakthidbtech.com=# copy student to '/opt/PostgresPlus/9.6 /data/new.txt';
COPY 3
-bash-3.2$ pwd
/opt/PostgresPlus/9.6/data
-bash-3.2$ cat new.txt
1 Ramanan
2 Dinesh
3 Richard
Transfering the data from flatfile of Operating System to student table into database
-bash-3.2$ pwd
/opt/PostgresPlus/9.6/data
-bash-3.2$ cat stud.txt
1 Naveen
2 viswa
3 Nijam
4 prakash
5 vicky
6 Ramanan
7 Dinesh
8 Richard
(8 rows)
www.sakthidbtech.com=# copy student from '/opt/PostgresPlus/9.1AS/data/stud.txt';
COPY 5
www.sakthidbtech.com=# select * from student;
sid | sname
-----+--------
1 Naveen
2 viswa
3 Nijam
4 prakash
5 vicky
6 Ramanan
7 Dinesh
8 Richard
(8 rows)
www.sakthidbtech.com=# create table emp_d(id integer,name text, dob date);
CREATE TABLE
www.sakthidbtech.com=# copy emp_d from '/u02/sss.csv' with delimiter ',';
COPY 5
www.sakthidbtech.com=# select * from emp_d;
1 | mala | 20-SEP-90 00:00:00
2 | tarun | 10-OCT-08 00:00:00
3 | lara | 12-JAN-09 00:00:00
4 | sara | 08-MAY-01 00:00:00
5 | guttu | 10-MAY-09 00:00:00
www.sakthidbtech.com=# copy emp_d to '/u02/sakthidbtech.csv' with delimiter ',' CSV HEADER;
COPY 5
[root@asmhost u02]# cat sakthidbtech.csv
id,name,dob
1, mala,20-SEP-90 00:00:00
2, tarun,10-OCT-08 00:00:00
3, lara,12-JAN-09 00:00:00
4, sara,08-MAY-01 00:00:00
5, guttu,10-MAY-09 00:00:00
[root@asmhost u02]#
www.sakthidbtech.com=# copy (select * from all_tables) to '/u02/ssslocation/sss_table.csv'with delimiter ',' CSV header;
COPY 17
[root@asmhost ssslocation]# cat sss_table.csv
owner,schemaname,table_name,table_space,status
sdbt,JOE,TEST_DF,,VALID
sdbt,PUBLIC,TEST_CK,,VALID
sdbt,JOE,TEST_UQ,,VALID
sdbt,JOE,TEST_PK,,VALID
sdbt,JOE,DEPT,,VALID
sdbt,JOE,STUD,,VALID
sdbt,JOE,T2,TBS,VALID
sdbt,JOE,T1,TBSONE,VALID
sdbt,JOE,STATE,,VALID
sdbt,JOE,CAPITAL,,VALID
sdbt,JOE,M_Y12_M09,,VALID
sdbt,JOE,MEASUREMENT,,VALID
sdbt,JOE,M_Y12_M10,,VALID
sdbt,JOE,TEST_D,,VALID
sdbt,JOE,LAND,,VALID
sdbt,JOE,LAND2,,VALID
sdbt,JOE,EMP_D,,VALID
www.sakthidbtech.com=# copy sss_d from '/u02/ssslocation/sss_table.csv'
www.sakthidbtech.com-# with delimiter ',' CSV HEADER;
COPY 17
www.sakthidbtech.com=# select * from sss_d;
sdbt | JOE | TEST_DF | | VALID
sdbt | PUBLIC | TEST_CK | | VALID
sdbt | JOE | TEST_UQ | | VALID
sdbt | JOE | TEST_PK | | VALID
sdbt | JOE | DEPT | | VALID
sdbt | JOE | STUD | | VALID
sdbt | JOE | T2 | TBS | VALID
sdbt | JOE | T1 | TBSONE | VALID
sdbt | JOE | STATE | | VALID
sdbt | JOE | CAPITAL | | VALID
sdbt | JOE | M_Y12_M09 | | VALID
sdbt | JOE | MEASUREMENT | | VALID
sdbt | JOE | M_Y12_M10 | | VALID
sdbt | JOE | TEST_D | | VALID
sdbt | JOE | LAND | | VALID
sdbt | JOE | LAND2 | | VALID
sdbt | JOE | EMP_D | | VALID
www.sakthidbtech.com=# copy sss_d(schemaname, table_name)
www.sakthidbtech.com-# to '/u02/ssslocation/newsss.csv'
www.sakthidbtech.com-# with delimiter ',';
COPY 17
[root@asmhost ssslocation]# cat newsss.csv
JOE,TEST_DF
PUBLIC,TEST_CK
JOE,TEST_UQ
JOE,TEST_PK
JOE,DEPT
JOE,STUD
JOE,T2
JOE,T1
JOE,STATE
JOE,CAPITAL
JOE,M_Y12_M09
JOE,MEASUREMENT
JOE,M_Y12_M10
JOE,TEST_D
JOE,LAND
JOE,LAND2
JOE,EMP_D
Comments
Post a Comment