Query Generator for postgreSQL based on psycopg2