Python and Advanced PostgreSQL with psycopg2 - SQL string composition with psycopg2