Skip to content

Enhance insert() API to support SELECT with input() for computed columns v2 #2726

Description

@suman-tercept

Current Limitation

The insert() method only supports direct table insertion, not SELECT statements
with transformations.

Desired Enhancement

Allow insert() to accept SELECT statements with input() function:

client.insert()
    .table("target_table")
    .query("SELECT col1, col2, col1 + col2 as computed FROM input('col1 Int32, col2 Int32')")
    .data(inputStream)
    .format(ClickHouseFormat.CSV)
    .send();

Or alternative syntax:

client.insert("INSERT INTO target_table SELECT col1, col2, col1 + col2 as computed FROM input('col1 Int32, col2 Int32')")
    .data(inputStream)
    .format(ClickHouseFormat.CSV)
    .send();

Use Case

We need to stream data with computed columns during insertion:

  • Stream large datasets efficiently
  • Apply transformations/computed columns on the fly
  • Leverage ClickHouse's input() function capabilities
  • Maintain the performance benefits of the streaming insert() API

Business Value

This is a common pattern in ClickHouse for ETL workloads where data needs
transformation during insertion without materializing intermediate results.

Current Workaround (Working but Undocumented)

We're successfully using this pattern in production:

String loadQuery = tableName + "(" + headers + ")" +
    " select " + parametersQuery + "* from input('" + csvHeadersStructure + "')";

try (InputStream inputStream = Files.newInputStream(Paths.get(filepath))) {
    InsertResponse response = client.insert(loadQuery, inputStream, ClickHouseFormat.CSVWithNames)
        .get(1200, TimeUnit.SECONDS);
}

This works but:

  • Not documented in official API docs
  • Unclear if this is intended behavior or might break in future versions
  • No IDE autocomplete/type safety for this pattern

Activity

  1. chernser commented on Jan 28, 2026

    @chernser
    Contributor

    Good day, @suman-tercept !

    Thank you for bringing this up!
    We will plan it in one of the next releases.

  2. suman-tercept commented on Jan 29, 2026

    @suman-tercept
    Author

    Thank you @chernser for the quick response!

    We're looking forward to the official support. Happy to help with testing or provide feedback once it's available.

  3. suman-tercept commented on Apr 28, 2026

    @suman-tercept
    Author

    Hi team, any update on this? We have this in production and would like to know if this is on the road map.
    We are actively using the undocumented workaround in production,
    since it's undocumented any client-v2 patch release could break it silently.

    Happy to test any proposed API changes or provide more details about our use case.

  4. polyglotAI-bot commented on Nov 28, 2026

    @polyglotAI-bot
    Collaborator

    Recommendation: Keep open — review PR #3460
    PR #3460 adds Client#insertQuery, which takes the application's INSERT statement. With its diff, the issue's INSERT INTO target_table SELECT … FROM input(…) form with CSV data inserts the computed column. The PR does not link this issue.

    Analysis: Each insert() method makes INSERT INTO <tableName> [(columns)] FORMAT <format> from its arguments (client-v2/src/main/java/com/clickhouse/client/api/Client.java:1846), so no method takes an INSERT … SELECT statement. The workaround works because the table name text goes into the SQL unchanged; the docs describe tableName only as a target table name (docs/clickhouse-docs/client.mdx:630).

    Automated triage by Polyglot AI. A maintainer makes the final decision.

  5. added
    client
    queries
    on Nov 28, 2026
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

    clientenhancementqueries

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions