Updated for postgresql