Postgres fix

Thank for merging #17, and fixing up some of the changes.

I've added some more fixes, which hopefully resolve this GROUP BY issues. This is caused due to MySQL extensions[1], which aren't compatible with postgresql.

I've hopefully fixed this now:
- I've switched groups on _folder.folder_ to _folder.id_, which is fine due to UNIQUE constraint on folder in the table.
- I've switched group on _file.folder_, _file.file_ to _file.id_. Again, UNIQUE constraint means this is fine.
- I've also changed the CASE statements to use COUNT on the appropriate field.

Hopefully, all these changes should also work with MySQL :wink:

I also had errors trying to upgrade my installation, but this was resolved by creating an empty SQL upgrade file. (I was getting `SQL error file DB function reports no errors`.)

[1]: http://dev.mysql.com/doc/refman/5.0/en/group-by-extensions.html