Re: import CSV file to a table

From: vinny <vinny(at)xs4all(dot)nl>
To: Günce Kaya <guncekaya14(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org, pgsql-general-owner(at)postgresql(dot)org
Subject: Re: import CSV file to a table
Date: 2017-03-08 14:45:48
Message-ID: 6bfaa830b0fca837623f6b48903dfdec@xs4all.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 2017-03-08 10:13, Günce Kaya wrote:
> Hi all,
>
> I want to import content of CSV file to a table via bash script
> without creating temporary table and I also want to skip some columns
> in CSV file (for instance, CSV file has 12 column and main table has
> only 2 column, If possible I would use only 2 column in CSV file) Is
> there any way to do it?
>
> Regards,
>
> --
>
> Gunce Kaya

This is more a programming question than a database question, and there
are many possible solutions.
Do *not*, whatever you do, try to write your own piece of code to read
the CSV. There are lots of unexpected
ways that the CSV file can be slightly different from what you expect,
and figuring all those out is a waste of time.
The example of embedded comma's is just one way, there could also be
newlines, linebreaks, utf8-escape characters etc.

Personally I'd go the python route because it's simple and
straightforward, but anything you are comfortable with will do.
If you are going to install additional software to do this then remember
that you'll need that same software again if
you need to do this again, or when you need to move this code to a
different server.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message John Iliffe 2017-03-08 14:52:00 Re: Unable to start postgresql
Previous Message Albe Laurenz 2017-03-08 14:15:39 Re: Request to confirm which command is use for exclusive operation