Db postgresql as base class

Use a common base class for postgresql based databases, which handles compiling of selects.