Rewrite of postgresql module to allow invocation by defined types

It now also support defining custom queries.

As a bonus, this rewrite is backward compatible (!)