Snowflake Queries

Snowflake Queries

Certified

Execute multiple SQL statements against Snowflake

Runs multiple SQL statements separated by semicolons in Snowflake cloud data warehouse. Snowflake natively supports multi-statement execution. Supports parameterized queries, transactions (default enabled), and all fetch modes. Default fetchSize is 10,000 rows.

yaml
type: io.kestra.plugin.jdbc.snowflake.Queries

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

yaml
id: snowflake_queries
namespace: company.team

tasks:
  - id: select
    type: io.kestra.plugin.jdbc.snowflake.Queries
    url: jdbc:snowflake://<account_identifier>.snowflakecomputing.com
    username: "{{ secret('SNOWFLAKE_USERNAME') }}"
    password: "{{ secret('SNOWFLAKE_PASSWORD') }}"
    sql: select * from demo_db.public.customers; select * from demo_db.public.emplyees;
    fetchType: FETCH
Installation

Our standard Docker images already include this plugin. If you use a -slim image or another setup, install it with the following command:

kestractl plugins get io.kestra.plugin:plugin-jdbc-snowflake --compatible-for $KESTRA_VERSION

For Kestra CLI, replace LATEST with a specific version or version range to pin the plugin version. For kestractl, use your Kestra version with --compatible-for, or specify an exact plugin version.

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

Assets this task consumes as inputs or produces as outputs, for lineage tracking and the asset graph (Enterprise Edition). A flow declaring this property on a task is rejected in the open-source edition.

Definitions
assetFailureBehaviorstring
Possible Values
IGNOREFAILWARN

Asset failure behavior

Behavior applied to the task state when a declared asset fails to render, emit, or be persisted (e.g. a lock conflict): FAIL escalates it to FAILED, WARN (default) warns it if it would otherwise succeed, IGNORE leaves the state untouched.

enableAutobooleanstring

Whether to auto-register assets referenced dynamically at runtime that are not statically declared in inputs or outputs.

inputsarray

The assets consumed as inputs.

id*string
Min length1
typestring
outputs

The assets produced as outputs.

id*string
Min length1
Max length150
type*object
descriptionstring
displayNamestring
metadataobject
Default{}
namespacestring
Min length1
Max length150
id*string
Min length1
Max length150
type*object
descriptionstring
displayNamestring
metadataobject
Default{}
namespacestring
Min length1
Max length150
id*string
Min length1
Max length150
type*object
descriptionstring
displayNamestring
metadataobject
Default{}
namespacestring
Min length1
Max length150
id*string
Min length1
Max length150
type*object
descriptionstring
displayNamestring
metadataobject
Default{}
namespacestring
Min length1
Max length150
id*string
Min length1
Max length150
type*object
descriptionstring
displayNamestring
metadataobject
Default{}
namespacestring
Min length1
Max length150
id*string
Min length1
Max length150
type*string
Min length1

Custom asset type

descriptionstring
displayNamestring
metadataobject
Default{}
namespacestring
Min length1
Max length150
Defaultfalse

Compute per-column statistics of the fetched rows

When true, writes an ION file with one entry per column (column, jdbcType, nulls, distinct (approximate), min, max, mean, median, minLen, maxLen) and exposes its URI in the columnStats output. Statistics are computed while the rows are read, without running a second query. Only applies to fetchType FETCH and STORE; LOB, binary and array columns are skipped. min and max are omitted for string columns longer than 256 characters, and median is computed on a bounded sample of the values

Default100000

Number of rows used to compute column statistics

Only used when columnStats is true. Statistics stop at this many rows while all rows are still fetched or stored. Must be at least 1. Default: 100,000

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.

Defaultfalse

Expose the executed SQL statement in the outputs

When true, the rendered SQL is exposed in the statement output, with the values of the secret() calls used in sql replaced by *** and truncated to 64 KiB. Disabled by default so that SQL text never leaks into outputs unless requested

Named parameter bindings for SQL query

Map of parameter names to values, bound to : name placeholders as prepared-statement parameters; supports nulls and typed values. Colons in literals, quoted identifiers, comments and :: casts are left as is; a : name missing from this map is bound to NULL with a warning.

The database user's password

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

Defaulttrue

Transaction

If one query failed, rollback transactions.

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.

SubTypeinteger

The number of affected rows for each query that doesn't return a result set

One entry per INSERT, UPDATE, DELETE or DDL statement, in execution order, as reported by the JDBC driver (DDL statements usually report 0). Queries returning a result set are not included here; their results are in outputs.

Total size of the stored result files in bytes

Only populated when fetchType is STORE

Formaturi

URI of the column statistics file in internal storage

Only populated when columnStats is true and fetchType is FETCH or STORE; columns of all result sets are merged by name

Total execution duration in milliseconds

Includes reading the result rows of every statement

The list of per-query outputs

Definitions
bytesinteger

Size of the stored result file in bytes

Only populated when fetchType is STORE

columnStatsstring
Formaturi

URI of the column statistics file in internal storage

Only populated when columnStats is true and fetchType is FETCH or STORE; file is stored in ION format

durationMsinteger

Statement execution duration in milliseconds

Includes reading the result rows

queryIdstring

Engine query identifier

The id the engine coordinator assigned to the query, for example the Trino query id. Not set when the engine does not expose one.

rowobject

First row of fetched data

Only populated when fetchType is FETCH_ONE

rowsarray
SubTypeobject

List of all fetched rows

Only populated when fetchType is FETCH

rowsAffectedinteger

Number of rows affected by the statement

Reported by the JDBC driver for INSERT, UPDATE, DELETE and similar statements. Not set when the statement returns a result set or when the driver does not report a count

sizeinteger

Number of rows fetched

Only populated when fetchType is FETCH or STORE

statementstring

Executed SQL statement

Only populated when outputStatement is true. Values of secret() calls are replaced by *** and the text is truncated to 64 KiB

tablesarray

Tables read or written by the statement

Detected from the SQL text, so this is a best effort: CTEs, temporary tables and dialect specific syntax can lower the confidence or be missed. Limited to 50 entries, see tablesTruncated

accessstring
Possible Values
READWRITECREATEDROP

How the statement uses the table

One of READ, WRITE, CREATE or DROP.

confidencestring
Possible Values
MEDIUMLOW

How reliable the detection is

MEDIUM when detected from the SQL text, LOW for temporary tables and ambiguous names.

databasestring

Database name

Null when the statement does not qualify the table with a database.

kindstring
Possible Values
TABLEFILEURL

Kind of source

Only set on DuckDB: TABLE, FILE or URL (files read through read_parquet, read_csv, ATTACH and quoted paths).

namestring

Table name

For DuckDB file reads, the file path or URL.

schemastring

Schema name

Null when the statement does not qualify the table with a schema.

tablesTruncatedboolean

Whether the tables list was cut at 50 entries

uristring
Formaturi

URI of stored results in internal storage

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

warningsinteger

Number of SQL warnings raised by the statement

Count of the SQLWarning chain reported by the driver, for example Postgres notices

Total number of rows affected by all statements

Sum of affectedRows. Not set when no statement reported an update count

Executed SQL statements

Only populated when outputStatement is true. Values of secret() calls are replaced by *** and the text is truncated to 64 KiB

Number of executed statements

When the driver runs the whole script in a single batch (transactional Snowflake, Redshift and Sybase scripts), the script counts as one statement

Formaturi

URI of the per-statement details file in internal storage

ION file with one {index, kind, rowsAffected, durationMs} entry per executed statement, plus queryId for engines that expose one (e.g. Trino).

Tables read or written by the statements

Detected from the SQL text, so this is a best effort: CTEs, temporary tables and dialect specific syntax can lower the confidence or be missed. Limited to 50 entries, see tablesTruncated

Definitions
accessstring
Possible Values
READWRITECREATEDROP

How the statement uses the table

One of READ, WRITE, CREATE or DROP.

confidencestring
Possible Values
MEDIUMLOW

How reliable the detection is

MEDIUM when detected from the SQL text, LOW for temporary tables and ambiguous names.

databasestring

Database name

Null when the statement does not qualify the table with a database.

kindstring
Possible Values
TABLEFILEURL

Kind of source

Only set on DuckDB: TABLE, FILE or URL (files read through read_parquet, read_csv, ATTACH and quoted paths).

namestring

Table name

For DuckDB file reads, the file path or URL.

schemastring

Schema name

Null when the statement does not qualify the table with a schema.

Whether the tables list was cut at 50 entries

Number of SQL warnings raised by the statements

Count of the SQLWarning chains reported by the driver across all statements

Unitbytes

The size of the stored result file.

The duration of the SQL execution, including reading the result rows.

Unitrows

The number of fetched rows.

Unitrows

The number of rows affected, as reported by the JDBC driver.