Snowflake Query

Snowflake Query

Certified

Execute a single SQL query against Snowflake

Runs one SQL statement and fetches results in Snowflake cloud data warehouse. 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.snowflake.Query

Execute a query and fetch results in a task, and update another table with fetched results in a different task.

yaml
id: snowflake_query
namespace: company.team

tasks:
  - id: select
    type: io.kestra.plugin.jdbc.snowflake.Query
    url: jdbc:snowflake://<account_identifier>.snowflakecomputing.com
    username: snowflake_user
    password: "{{ secret('SNOWFLAKE_PASSWORD') }}"
    sql: SELECT * FROM demo_db.public.customers
    fetchType: FETCH

  - id: generate_update
    type: io.kestra.plugin.jdbc.snowflake.Query
    url: jdbc:snowflake://<account_identifier>.snowflakecomputing.com
    username: snowflake_user
    password: "{{ secret('SNOWFLAKE_PASSWORD') }}"
    sql: "INSERT INTO demo_db.public.customers_new (year_month, store_code, update_date) values {% for row in outputs.select.rows %} ({{ row.year_month }}, {{ row.store_code }}, TO_DATE('{{ row.date }}', 'MONTH DD, YYYY') ) {% if not loop.last %}, {% endif %} {% endfor %}"
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.

Specifies the default database to use once connected

The specified database should be an existing database for which the specified default role has privileges. If you need to use a different database after connecting, execute the USE DATABASE command.

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.

Private key used for Snowflake key-pair authentication

Kestra supports multiple private key formats for Snowflake key-pair authentication.

You can provide your key in any of the following formats:

  1. PKCS8 DER (base64-encoded, single-line)

  2. PEM PKCS8: -----BEGIN PRIVATE KEY----- ... -----END PRIVATE KEY-----

  3. PEM PKCS1 RSA: -----BEGIN RSA PRIVATE KEY----- ... -----END RSA PRIVATE KEY-----

  4. Multiline or single-line input (Kestra will normalize automatically)

  5. Encrypted PKCS8 (requires providing privateKeyPassword)

Recommended format

Snowflake recommends PKCS8. If your key is in PKCS1 format, Kestra will automatically convert it.

Example: using a PEM PKCS8 key (recommended)

secret('SNOWFLAKE_PRIVATE_KEY') should contain:

-----BEGIN PRIVATE KEY----- MIIEvQIBADANBgkqhkiG9w0BAQEFAASC... ... -----END PRIVATE KEY-----

Example: encrypted private key

privateKey: "{{ secret('SNOWFLAKE_PRIVATE_KEY') }}" privateKeyPassword: "{{ secret('SNOWFLAKE_PRIVATE_KEY_PASSWORD') }}"

Converting a PEM key to unencrypted PKCS8 DER (optional)

openssl pkcs8 -topk8 -nocrypt -inform PEM -outform DER
-in private_key.pem
-out private_key.der

base64 -w 0 private_key.der > private_key.base64

You can then store the content of private_key.base64 as the Kestra secret.

Kestra automatically detects the format and performs the necessary conversions. No manual header stripping or reformatting is required.

Specifies the private key password for key pair authentication and key rotation

Query tag for Snowflake session tracking

Optional string to tag queries executed within the session for monitoring and cost allocation

Specifies the default access control role to use in the Snowflake session initiated by the driver

The specified role should be an existing role that has already been assigned to the specified user for the driver. If the specified role has not already been assigned to the user, the role is not used when the session is initiated by the driver. If you need to use a different role after connecting, execute the USE ROLE command.

Specifies the default schema to use for the specified database once connected

The specified schema should be an existing schema for which the specified default role has privileges. If you need to use a different schema after connecting, execute the USE SCHEMA command.

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

The database user

Specifies the virtual warehouse to use once connected

The specified warehouse should be an existing warehouse for which the specified default role has privileges. If you need to use a different warehouse after connecting, execute the USE WAREHOUSE command to set a different warehouse for the session.

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.