sql: import reduce from compatibility for py3