Fixing bug in next_timestamp pg function