Re: Assistance with importing a csv into a PostgreSQL database

From: Michael Wood <esiotrot(at)gmail(dot)com>
To: Frank Bax <fbax(at)sympatico(dot)ca>
Cc: PostgreSQL List - Novice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Assistance with importing a csv into a PostgreSQL database
Date: 2009-08-06 12:27:52
Message-ID: 5a8aa6680908060527m7d2e439cnbbd08d46810440d0@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

2009/8/6 Frank Bax <fbax(at)sympatico(dot)ca>:
> Intengu Technologies wrote:
>>
>> Please assist me with how to import a csv file into PostgreSQL that
>> has the following structure - http://pastebin.com/m56bb6cb2.
>>
>> The challenges are these:
>> 1. import the whole csv into one table - problem is the number of
>> fields will not be the same for the various rows, the csv has no field
>> names
>> 2. split this one table into the various tables - a total of 6 tables
>> 3. update the field names with the correct names
>
> create table intengu1 (...)
> create table intengu2 (...)
> create table intengu3 (...)
> create table intengu4 (...)
> create table intengu5 (...)
> create table intengu6 (...)
>
> grep ^.1. /tmp/intengu.txt | psql -c "copy intengu1 from STDIN CSV;"
> grep ^.2. /tmp/intengu.txt | psql -c "copy intengu2 from STDIN CSV;"
> grep ^.3. /tmp/intengu.txt | psql -c "copy intengu3 from STDIN CSV;"
> grep ^.4. /tmp/intengu.txt | psql -c "copy intengu4 from STDIN CSV;"
> grep ^.5. /tmp/intengu.txt | psql -c "copy intengu5 from STDIN CSV;"
> grep ^.6. /tmp/intengu.txt | psql -c "copy intengu6 from STDIN CSV;"

heh :)

Good point. I probably need some sleep.

--
Michael Wood <esiotrot(at)gmail(dot)com>

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Michael Wood 2009-08-06 12:35:56 Re: Assistance with importing a csv into a PostgreSQL database
Previous Message Intengu Technologies 2009-08-06 11:47:37 Re: Assistance with importing a csv into a PostgreSQL database