Use substring to work with PostgreSQL 9.0+