Fixed SQL syntax to work with PostgreSQL 9.3