Complete the migration from SQLite3 to Postgres 9.2.2

All tests are green in the database package.  Some clean-up has to be done in the SQL queries, mostly formatting.

The test are kind of slow compared to SQLite3, I suspect because every test connects then disconnects from the DB, which must be longer with PG than with SQLite.

Will need to do some real benchmarks to verify if there's any problem with slow queries or functions.