adjusted custom SQL to work with PostgreSQL