Re: How to Create Table from CSV

From: Rich Shepard <rshepard(at)appl-ecosys(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: How to Create Table from CSV
Date: 2011-03-06 19:20:09
Message-ID: alpine.LNX.2.00.1103061117030.23837@salmo.appl-ecosys.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sun, 6 Mar 2011, ray wrote:

> I would like to create a table from a CSV file (the first line is
> headers which I want to use as column names) saved from Excel. I have
> a new database which I have been able to create tables from a
> tutorial. But I haven?t been able to produce this new table. The
> following are my attempts:

As mentioned, write the table structure to a file using the postgres DDL.
That is, 'CREATE TABLE <name> (
column1...
);'

Then using psql you can '\copy to <tablename> from <filename> with delimiter
as ',' null as '' CSV' (without the quotes and with appropriate delimiter
and null values. The backslash is needed to make it work.

Rich

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Eduardo 2011-03-06 19:33:01 Re: Web Hosting
Previous Message Vibhor Kumar 2011-03-06 18:59:06 Re: How to Create Table from CSV