Gateways and some fixes for dp statements using postgres