[Python] Is it possible to name nested dict keys as SQL parameter?

Discussão em 'Python' iniciado por Stack, Junho 1, 2025.

  1. Stack

    Stack Membro Participativo

    query = ("""
    INSERT INTO person
    (id, name, country_id)
    VALUES
    (%(id)s, %(name)s, %(country[id])s)
    """)

    person = {'id': 1, 'name': 'First Last', 'country': {'id': 1, 'name': 'USA'}}
    cursor.execute(query, person)


    Is it possible to accomplish something like this for naming person['country']['id'] in the query string?

    Continue reading...

Compartilhe esta Página