Re: [GENERAL] import CSV file to a table - Mailing list pgsql-general

From vinny
Subject Re: [GENERAL] import CSV file to a table
Date
Msg-id 6bfaa830b0fca837623f6b48903dfdec@xs4all.nl
Whole thread Raw
In response to [GENERAL] import CSV file to a table  (Günce Kaya <guncekaya14@gmail.com>)
Responses Re: [GENERAL] import CSV file to a table  (John McKown <john.archie.mckown@gmail.com>)
List 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.


pgsql-general by date:

Previous
From: Albe Laurenz
Date:
Subject: Re: [GENERAL] Request to confirm which command is use for exclusiveoperation
Next
From: John Iliffe
Date:
Subject: Re: [GENERAL] Unable to start postgresql