help copy *.txt to postgres


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help copy *.txt to postgres
# 1  
Old 05-16-2011
help copy *.txt to postgres

hi all,
a have problem to load *.txt to postgres

my database:
Code:
id_list_ip (nextval)
list_ip (varchar)

txt file (list_ip.txt)
Code:
hasilping_10.8.248.1
hasilping_119.110.112.226
hasilping_119.110.125.33
hasilping_125.22.1.25
hasilping_192.168.2.1
hasilping_202.73.96.70


script (list_ip.sh)
Code:
#!/bin/sh

cd /usr/lib/postgresql/8.4/bin
./psql -U postgres -d NMS << EOF
COPY "list_ip" ("id_list_ip","list_ip") FROM '/opt/Tampung1/list_ip.txt';

how to insert the txt file to postgres with id_list_ip auto-increment?

thanks in advance

Last edited by pludi; 05-16-2011 at 04:55 AM.. Reason: Please use code tags
# 2  
Old 05-16-2011
I think you need a staging table, because you are inserting one column and autoincrementing the other, which is not copy-friendly. Copy to the staging table, and then insert to the list_ip column, and the other column will autoincrement. Remember to clear your staging table on each run.
# 3  
Old 05-18-2011
OK thank DGPickett ...I'll try it..
# 4  
Old 05-19-2011
With RDBMS, the big bottleneck is getting the data in; moving it internally is relatively fast and simple. Some RDBMS have ways to map a text file as an external table, which is very fast, or to stream data into the insert statement using a SP and UDFs (the sp is like a table, and inside, it has udf calls to get the right field or substring of the current record for each virtual column, and a where clause udf call does the read and eof test). I like the streaming, using pipe.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Copy the content from txt file and create a html file

I have a txt file with a list of error messages in a xml tag format, and each error message is separated with a identifier(endresult).Need to split that and copy and create a new html file.Error message has some special character. how to escape the special character and insert my data into the... (7 Replies)
Discussion started by: DevAakash
7 Replies

2. UNIX for Beginners Questions & Answers

Copy txt file into excel vbscript

Hi everybody, I am working on Windows 10 and using cygwin. I have a vbscript as follows: Set objExcel = CreateObject("Excel.Application") objExcel.Visible = True Set wb1 = objExcel.Workbooks.open("\\files\share\path\file1.xlsx") wb1.Worksheets("Sheet1").Range("A1:CR89").Clear Set... (0 Replies)
Discussion started by: supernono06
0 Replies

3. Shell Programming and Scripting

Copy data to CSV file from txt output

Hi Everyone , Below is output from a TL1 , I want just the NE Name: and beside that the Temperature and the voltages in a csv file , Is this possible? > act-user:AB1S2a:ArshadFO:493::**********; AB1S2a 2016-02-07 10:13:24 M 493 COMPLD "ArshadFO:2016-02-07 10-04-55,0" ;... (11 Replies)
Discussion started by: adgjmpt
11 Replies

4. UNIX for Dummies Questions & Answers

How to copy a file opened in UNIX to word or txt?

Hi I would like to know how to copy a file opened in unix editor like Nedit or vi editor to a word document Since I am newbie I want to make sure I am not really copying onto real subdirectories I tried to right click and copy the entire .sql file or any other file opened.. Nedit doesn't... (3 Replies)
Discussion started by: swathi123
3 Replies

5. Shell Programming and Scripting

Postgres in Linux

I have this 15 postgres sql queries similar to below to run in linux... Its taking a lot of time to run (3hours) . can any one plz guide me how can i reduce the time of execution execute 'insert into cc.rpt_cons_sub_ccdb_data(report_date, server_name, report_type, count) select... (3 Replies)
Discussion started by: nikhil jain
3 Replies

6. Shell Programming and Scripting

Read input txt while find copy

I have a text file called file.txt which has a list of file as shown below that i need to find and copy to a particular location. FILENAMES skter.pdf abcdf.sas tereen.lst abc12.txt i am using following code and it never works however i try it. cat file.txt | while read FILENAME;do find... (4 Replies)
Discussion started by: MILAN KUMAR
4 Replies

7. Shell Programming and Scripting

How to copy specific file.txt in specific folder?

hye there... i have a problem to copy file in specific folder that will change the name according to host,time(%m%s) and date(%Y%M%D) example folder name: host_20100531.154101801 this folder name will always change... but i just want to copy the AAA.txt and BBB.txt file.. really need... (17 Replies)
Discussion started by: annetote
17 Replies

8. Solaris

Copy and paste text from a word document into a txt file in vi

Hello, Can anybody please tell me how we can copy and paste text from a word document into a text file that we are editing in vi? Is it possible to do that while we are editing the text file in vi in insert mode? Thanks, (3 Replies)
Discussion started by: Pouchie1
3 Replies

9. UNIX for Dummies Questions & Answers

echo "ABC" > file1.txt file2.txt file3.txt

Hi Guru's, I need to create 3 files with the contents "ABC" using single command. Iam using: echo "ABC" > file1.txt file2.txt file3.txt the above command is not working. pls help me... With Regards / Ganapati (4 Replies)
Discussion started by: ganapati
4 Replies

10. Shell Programming and Scripting

Read from fileList.txt, copy files from directory tree

Hi, hopefully this is a fairly simple Q&A. I have a clean file list of approximately 180 filenames with no directory or slashes in front of the filename nor any extension or dot ".". I would like to read from this list, find these files recursively down through directory trees, copy the files... (1 Reply)
Discussion started by: fxvisions
1 Replies
Login or Register to Ask a Question