Bug fix: syntax change by changing SQL->PLPGSQL. Handle psycopg2.cursor.nrows() return = -1 case --kazu