Fixed SQL syntax to work with PostgreSQL 9.3
Merged from 5.2: compatibility with PostgreSQL 9.3