Skip to content

Proper way to batch queries? #3331

Open
@rberg89

Description

I have a large amount of UPDATE statements to make. The most efficient way I have found, however slow, is:

await Promise.all(largeBatchOfQueries.map(async (query) => {
    const client = await pool.connect();
    await client.query(query.sql, [
        query.param1,
        query.param2,
        query.param3,
        query.param4
    ])
    await client.release();
}));

~160k UPDATEs takes ~2.5 minutes which is too slow for my situation. ~30 max connections in pool gives me the best time.

I saw there is discussion around the topic but not sure if I need a different approach or to add another library. Wondering if anyone has any insight, much appreciated.
#1388

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions