Adding working version of postgress code