Correct event sql for postgres SQL