Here's how I managed to do it quite rapidly:
- Remove all the constraints and indexes from the table.
- Prepare your data in a CSV file that you put on the DB server.
- Open a console on the DB server: psql -d myDb
- And here comes the star of the show, the COPY statement:
COPY myTable (theFirstColumn, theSecondColumn) FROM '/path/to/some/file.csv' WITH CSV;
Append QUOTE AS '"' DELIMITER AS ',' ESCAPE AS '\' if required.
The table definition is not required if the columns in your file match their order in the table, but I would recommend against it. - Add the constraints and indexes
If you really have to use INSERT statements, at least put them in one big transaction.
Note it is not going to check against NOT NULL!
Note it is not going to check against NOT NULL!
No comments:
Post a Comment