|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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... |
|
#2
|
||||
|
||||
|
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 |
|
#3
|
|||
|
|||
|
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? |
|
#4
|
||||
|
||||
|
Quote:
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. |
![]() |
| Viewing: Dev Shed Forums > Databases > PostgreSQL Help > Importing CSV file |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|