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