create a script which imports csv data

Поиск
Список
Период
Сортировка
От Robert Buckley
Тема create a script which imports csv data
Дата
Msg-id 1340884387.36134.YahooMailNeo@web133002.mail.ir2.yahoo.com
обсуждение исходный текст
Ответы Re: create a script which imports csv data  (Raymond O'Donnell <rod@iol.ie>)
Re: create a script which imports csv data  ("Marc Mamin" <M.Mamin@intershop.de>)
Re: create a script which imports csv data  (Berend Tober <btober@broadstripe.net>)
Re: create a script which imports csv data  (Craig Ringer <ringerc@ringerc.id.au>)
Список pgsql-general
Hi,

I have to create a script which imports csv data into postgresql ...and have a few questions about the best way to do it.

The csv data is automatically created from an external database so I have no influence over which columns etc are downloaded.

The csv comes without an fid field and has therefore no unique identifier.

How can I best create a table for the import?  

Would I first create a table without an fid and then after the import create a sequence and add the sequence to the table, then somehow update the fid field?

could anyone show me the best way to do this?


at the moment I am doing this...which makes postgresql throw an error because obviously the 'fid' field is missing from the csv data!

CREATE SEQUENCE fid_seq INCREMENT 1 START 1;

CREATE TABLE Anlagenregister_Aktuell_2011 (
fid INTEGER NOT NULL DEFAULT nextval('fid_seq'),
Firma TEXT,
Anlagenschluessel TEXT,
Anschrift TEXT,
PLZ TEXT,
Ort TEXT,
Bundesland TEXT,
Energietraeger TEXT,
Inbetriebnahmedatum DATE,
Netzzugangsdatum DATE,
Netzabgangsdatum DATE,
Ausserbetriebnahmedatum DATE,
Installierte_Leistung_kW numeric(11,4),
Lastgangmessung TEXT,
Einspeisemanagement TEXT,
Spannungsebene TEXT,
Zaehlpunktbezeichnung TEXT,
Anlagentyp TEXT,
Geographische_Koordinaten TEXT,
Schalloptimierung TEXT,
Biomasse_KWK_Bonus TEXT,
Biomasse_Technologie_Bonus TEXT,
PRIMARY KEY (fid)
);

copy Anlagenregister_Aktuell_2011 FROM '/var/www/Anlagenregister_Aktuell_2011.csv' DELIMITERS ';' CSV;


thanks,

Rob

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

Предыдущее
От: "Marc Mamin"
Дата:
Сообщение: function lookup using a "real" function call
Следующее
От: Raymond O'Donnell
Дата:
Сообщение: Re: create a script which imports csv data