Skip to content

Most performant method to update many records? #801

Answered by elprans
StayFoolisj asked this question in Q&A

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

You must be logged in to vote
1 reply
@DoobyDouglas

Answer selected by StayFoolisj

You must be logged in to vote
4 replies
@elprans

@StayFoolisj

@elprans

@bobir01

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