[Python] Len of SQL result dependent on order of selected cols? Python

Discussão em 'Python' iniciado por Stack, Agosto 7, 2025.

  1. Stack

    Stack Membro Participativo

    I have an excerpt of code that looks like this, with the actual connection information and cols/table. For some reason the order of the cols appears to be affecting the length of the output, which makes no sense to me. Does anyone know what might be causing it?

    import mysql.connector
    connection = mysql.connector.connect(
    ...
    )
    cursor = connection.cursor(buffered=True, dictionary=True)


    q1 = """

    select col1, col2 from table
    """

    cursor.execute(q1)
    res = cursor.fetchall()
    print('len of res for q1', len(res))

    q2 = """

    select col2, col1 from table
    """

    cursor.execute(q2)
    res = cursor.fetchall()
    print('len of res for q2', len(res))

    connection.close()


    Output:


    len of res for q1 50597
    len of res for q2 1032
    ​

    The version of mysql-connector-python is: 2.2.9 and the db engine is MyISAM

    Shouldn't the number of rows in the outputs to each query be the same?

    Continue reading...

Compartilhe esta Página