Adapt code for PostgreSQL