Postgresql compatibility for agent model

Extracted RDBMS specific function to a seperate module