Efficient bulk updates with asyncpg

Let’s imagine that we have a database table with domains and related ip addresses and nameservers for each domain. We want to make updates for multiple records per one query rather than execute update for each domain.

Here is sample python list which consists of tuples with primary key, timestamp, nameserver list, and ip address list. This structure is used in a code below, for updates.

I have created special type for such record in PostgreSQL:

Here is a sample code to update multiple domains per one query:

Leave a Reply

Your email address will not be published. Required fields are marked *