Clickhouse Query

Clickhouse Query

Certified

Execute a single SQL query against ClickHouse

Runs one SQL statement and fetches results from ClickHouse columnar database. Supports parameterized queries, transactions with afterSQL, and multiple fetch modes (FETCH, FETCH_ONE, STORE). Default fetchSize is 10,000 rows for STORE mode.

yaml
type: io.kestra.plugin.jdbc.clickhouse.Query

Query a Clickhouse database.

yaml
id: clickhouse_query
namespace: company.team

tasks:
  - id: query
    type: io.kestra.plugin.jdbc.clickhouse.Query
    url: jdbc:clickhouse://127.0.0.1:56982/
    username: "{{ secret('CLICKHOUSE_USERNAME') }}"
    password: "{{ secret('CLICKHOUSE_PASSWORD') }}"
    sql: SELECT * FROM clickhouse_types
    fetchType: STORE

Ingest data to and query data from ClickHouse

yaml
  id: query_clickhouse
  namespace: company.team

  tasks:
    - id: create_database
      type: io.kestra.plugin.jdbc.clickhouse.Query
      sql: CREATE DATABASE IF NOT EXISTS helloworld

    - id: create_table
      type: io.kestra.plugin.jdbc.clickhouse.Query
      sql: |
        CREATE TABLE IF NOT EXISTS helloworld.my_first_table
        (
            user_id String,
            message String,
            timestamp DateTime,
            metric Float32
        )
        ENGINE = MergeTree()
        PRIMARY KEY (user_id, timestamp)

    - id: insert_data
      type: io.kestra.plugin.jdbc.clickhouse.Query
      sql: |
        INSERT INTO helloworld.my_first_table (user_id, message, timestamp,
        metric) VALUES
            (101, 'Hello, ClickHouse!',                                 now(),       -1.0    ),
            (102, 'Insert a lot of rows per batch',                     yesterday(), 1.41421 ),
            (102, 'Sort your data based on your commonly-used queries', today(),     2.718   ),
            (101, 'Granules are the smallest chunks of data read',      now() + 5,   3.14159 )

    - id: query_and_store_as_json
      type: io.kestra.plugin.jdbc.clickhouse.Query
      sql: SELECT user_id, message FROM helloworld.my_first_table
      fetchType: STORE

  pluginDefaults:
    - type: io.kestra.plugin.jdbc.clickhouse.Query
      values:
        url: jdbc:clickhouse://host.docker.internal:8123/
        username: default
Properties

SQL statement(s) to execute

Runs one or more SQL statements rendered with flow variables. Query tasks accept a single statement; Queries tasks can execute multiple statements separated by semicolons

The JDBC URL to connect to the database

SQL to execute after main query in same transaction

Optional SQL executed in the same transaction after the main statement. Useful for marking rows as processed to avoid duplicates; only a single statement is allowed. Commit covers both sql and afterSQL

Default10

Maximum number of pooled connections

Maximum connections held in the pool for a given URL and credentials. Default 10. Increase for flows that run many concurrent queries against the same database to avoid waiting for an available connection. Ignored when connectionPooling is false or for embedded drivers.

Defaulttrue

Reuse database connections via a connection pool

When true (default), connections are pooled and reused across executions, keyed by URL and credentials, removing the connect and TLS-handshake cost on each run. Set to false if your SQL relies on session state persisting on the connection (for example SET search_path, session-scoped temp tables or variables), since pooled connections are reused. Embedded drivers (DuckDB, SQLite, MS Access) never pool regardless of this setting.

Default10000

Number of rows to fetch per database round trip

Controls JDBC fetch size for STORE mode. Default: 10,000 rows; use Integer.MIN_VALUE for MySQL streaming. Ignored for FETCH and FETCH_ONE

DefaultNONE
Possible Values
STOREFETCHFETCH_ONENONE

Result fetching mode

FETCH returns all rows, FETCH_ONE returns the first row only, STORE streams rows to internal storage (ION), NONE returns no data. Default: NONE

SubTypestring

Output file names to capture after SQL execution

Creates named temporary files in the task working directory before the SQL runs, making their absolute paths available as {{ outputFiles.name }} Pebble variables in the SQL template. Only supported by embedded, in-process drivers (DuckDB, SQLite) where the database engine writes to the same filesystem as the Kestra worker. Remote database drivers (Postgres, MySQL, etc.) do not support this — they execute SQL on a separate server that cannot write to the Kestra worker filesystem.

Named parameter bindings for SQL query

Map of parameter names to values. Use : name placeholders rendered then bound as prepared-statement parameters; supports nulls and typed values

The database user's password

Reference (ref) of the pluginDefaults to apply to this task.

The time zone id to use for date/time manipulation. Default value is the worker's default time zone id

The database user

First row of fetched data

Only populated when fetchType is FETCH_ONE

SubTypeobject

List of all fetched rows

Only populated when fetchType is FETCH

Number of rows fetched

Only populated when fetchType is FETCH or STORE

Formaturi

URI of stored results in internal storage

Only populated when fetchType is STORE; file is stored in internal storage using ION format

Unitrows

The number of fetched rows.