Re: Create a pg table from CSV with header rows

Поиск
Список
Период
Сортировка
От Doug Bloebaum
Тема Re: Create a pg table from CSV with header rows
Дата
Msg-id caa2de8a0509160741776f5f45@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Create a pg table from CSV with header rows  (Michael Fuhr <mike@fuhr.org>)
Ответы Re: Create a pg table from CSV with header rows  (David Fetter <david@fetter.org>)
Список pgsql-general
On 9/15/05, Michael Fuhr <mike@fuhr.org> wrote:
On Thu, Sep 15, 2005 at 06:48:59PM -0400, Robert Fitzpatrick wrote:
> Anyone know a package that can do this? Perferrably a Unix/Linux
> package.

It would be trivial to write a script in a language like Perl to
read the first line of a file and generate a CREATE TABLE statement
from it, then issue a COPY command and send the rest of the file.
Determining the columns' data types would be a different matter:
if they weren't specified in the header then you'd have to guess
or perhaps make them all text.

I've attached a sample implementation of Michael's suggestion.


Вложения

В списке pgsql-general по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: new.id has wrong value in INSERT RULE
Следующее
От: Peter Eisentraut
Дата:
Сообщение: Re: Question about a query plan