PostgreSQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesPostgreSQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 25th, 2009, 03:46 AM
PGGuru PGGuru is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 24 PGGuru User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 37 m 43 sec
Reputation Power: 0
Importing CSV file

Hi,
I want to a import a CSV file into a postgres table. I'm aware of COPY command, but what I want is import only the selected columns from file also in order I want.
Currently with COPY command I'm not able to figure out how to select only required columns.

Any ideas...

Reply With Quote
  #2  
Old June 25th, 2009, 04:48 AM
pgFrank's Avatar
pgFrank pgFrank is offline
So help me Codd
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Location: Brazil
Posts: 306 pgFrank User rank is Sergeant (500 - 2000 Reputation Level)pgFrank User rank is Sergeant (500 - 2000 Reputation Level)pgFrank User rank is Sergeant (500 - 2000 Reputation Level)pgFrank User rank is Sergeant (500 - 2000 Reputation Level)pgFrank User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 14 h 35 m 11 sec
Reputation Power: 20
You have to import the complete file. But, you can import the file in a temporary table and then select only the columns you need in the order you want and insert these records in your target table.

It's an extra step, but it won't take too much effort and time.
__________________
PostgreSQL-manual

Reply With Quote
  #3  
Old June 25th, 2009, 04:53 AM
PGGuru PGGuru is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 24 PGGuru User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 37 m 43 sec
Reputation Power: 0
Thanks for the reply frank.
Actually I wanted avoid that step.
As my CSV files are very huge and I need to import such 4-5 such files daily. So inserting them twice will be a big overhead and time consuming.

Is there anything similer to OPENROWSET of SQL Server in POstgreSQL?

Reply With Quote
  #4  
Old June 25th, 2009, 07:51 AM
pgFrank's Avatar
pgFrank pgFrank is offline
So help me Codd
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Location: Brazil
Posts: 306 pgFrank User rank is Sergeant (500 - 2000 Reputation Level)pgFrank User rank is Sergeant (500 - 2000 Reputation Level)pgFrank User rank is Sergeant (500 - 2000 Reputation Level)pgFrank User rank is Sergeant (500 - 2000 Reputation Level)pgFrank User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 14 h 35 m 11 sec
Reputation Power: 20
Quote:
So inserting them twice will be a big overhead and time consuming.

There will be overhead and it will take some time, but still can be very fast. There will be only one insert (copy) per file and then a INSERT INTO ... SELECT for each of these files. The difference might be just a few seconds or minutes, you have to test to know what it will be.

I'm not familiar with SQL Server, but I think you're looking for something like dblink to connect to another database (-server). It's not in the core of PostgreSQL but installing from the contrib is very easy.

If you need some other type of connection, pl/perl or pl/python can help you out.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesPostgreSQL Help > Importing CSV file


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek