Sunday, October 11, 2015

Populating a PostgreSQL table / database

The other day I had to populate a table with hundreds of millions of records.
Here's how I managed to do it quite rapidly:

  1. Remove all the constraints and indexes from the table.
  2. Prepare your data in a CSV file that you put on the DB server.
  3. Open a console on the DB server: psql -d myDb
  4. 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.
  5. 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!

Wednesday, October 7, 2015

OS X 10.11 El Capital hangs when plugging a USB device in VMware Workstation 12.0

The other day I tried to "hot plug" my iPad into OS X running as a guest, which consistently resulted in the guest OS freezing / hanging with no other solution than reboot it.

I haven't found a real solution for this, nor do I really care to investigate the problem. My workaround is to connect it before OS X starts, and this way it's properly recognized.

A quick example about geofencing (sorry, "region monitoring") on iOS with Swift is coming up!