| From: | John DeSoi <desoi(at)pgedit(dot)com> | 
|---|---|
| To: | c b <charles(dot)blankenship(at)gmail(dot)com> | 
| Cc: | pgsql-novice(at)postgresql(dot)org | 
| Subject: | Re: importing a data file without defining a table structure | 
| Date: | 2010-07-29 18:13:33 | 
| Message-ID: | F7D89700-C5E1-4014-9B84-C1412BFCDA29@pgedit.com | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-novice | 
On Jul 22, 2010, at 4:21 PM, c b wrote:
> What's the quickest and easiest way to load data into tables from
> external files.
> 
> I've dug around a bit and it may be the case that people just don't do
> what I'm looking to do, so I'm asking here.
> 
> I've got a csv file with column names in the first row.  I want to
> load that into a table and have the column types and names generated
> automatically.
> 
> Can this be done?  (Or do I need to first create a table with CREATE,
> typing out each column name and data type manually, and then edit the
> data file to remove the first row, and then copy the file into the
> table using COPY?)
No, Postgres does not automatically create the table structure for you. But not too difficult to implement with your favorite scripting language. I use this method to bulk load tables from other systems and then write views and functions to convert it to the format I need.
John DeSoi, Ph.D.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Leon Starr | 2010-07-29 22:31:55 | Trouble accessing %ROWTYPE attributes returned by function | 
| Previous Message | JORGE MALDONADO | 2010-07-29 16:53:35 | ASSIGNING TABLE PRIVILEGES |