Skip to content

Feature request: Support for pgx batching #1275

Description

@johanbrandhorst

As mentioned in #472, pgx batching can be a very important tool for efficient inserts and queries. There doesn't seem to be any way to use the generated methods with the existing pgx batching interface. The pgx batching interface is defined by the Batch type and its Queue method. It would be neat if we could have something similar to the generated New(db DBTX) *Queries function that operates on a pgx.Batch.

We'd need to think a little about the design, since in an ideal world we'd still be able to get typed responses for each entry on the batch. Maybe each function on the type that operates on a batch should take a callback or something for how to process the returned data?

Activity

  1. Jille commented on Dec 21, 2021

    @Jille
    Contributor

    #1352 could at least alleviate the inserting part of this, but CopyFrom can't do everything regular inserts can do.

  2. danielbprice commented on Jan 6, 2022

    @danielbprice
    Contributor

    For what it's worth, I recently migrated some code from "one insert at a time" to "1000 inserts in a batch" and got at least 100x speedup (it's now so fast I don't care). As a result, I more-or-less can't use sqlc in my project, even though I'd like to.

  3. fedorkanin commented on Sep 23, 2024

    @fedorkanin

    As far as I understand, currently there is still no support for batching different kinds of queries, is there? This would be really handy, as it's going to reduce the number of roundtrips for complex queries.

  4. jgiles commented on Mar 30, 2026

    @jgiles

    See #4342 for batching different kinds of queries

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions