Changed postgresql code