Skip to content

Most performant method to update many records? #801

Answered by elprans
StayFoolisj asked this question in Q&A
Discussion options

You must be logged in to vote

Indeed, use executemany:

updates = [(account_id, new_address, additional_protocol) from <data_source>]

await connection.executemany(
    """
    UPDATE accounts
    SET 
      address = $2,
      protocols_used = array_append(protocols_used, $3)
    WHERE
      id = $1
    """,
    updates,
)

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
1 reply
@DoobyDouglas
Comment options

Answer selected by StayFoolisj
Comment options

You must be logged in to vote
4 replies
@elprans
Comment options

@StayFoolisj
Comment options

@elprans
Comment options

@bobir01
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants