
PostgreSQL Query
CertifiedExecute a single SQL query against PostgreSQL
PostgreSQL Query
Execute a single SQL query against PostgreSQL
Runs one SQL statement and fetches results. Supports parameterized queries, transactions with afterSQL, and multiple fetch modes (FETCH, FETCH_ONE, STORE). Default fetchSize is 10,000 rows for STORE mode.
type: io.kestra.plugin.jdbc.postgresql.QueryExamples
Execute a query and fetch results in a task, and update another table with fetched results in a different task.
id: postgres_query
namespace: company.team
tasks:
- id: fetch
type: io.kestra.plugin.jdbc.postgresql.Query
url: jdbc:postgresql://127.0.0.1:56982/
username: "{{ secret('POSTGRES_USERNAME') }}"
password: "{{ secret('POSTGRES_PASSWORD') }}"
sql: SELECT concert_id, available, a, b, c, d, play_time, library_record, floatn_test, double_test, real_test, numeric_test, date_type, time_type, timez_type, timestamp_type, timestampz_type, interval_type, pay_by_quarter, schedule, json_type, blob_type FROM pgsql_types
fetchType: FETCH
- id: use_fetched_data
type: io.kestra.plugin.jdbc.postgresql.Queries
url: jdbc:postgresql://127.0.0.1:56982/
username: "{{ secret('POSTGRES_USERNAME') }}"
password: "{{ secret('POSTGRES_PASSWORD') }}"
sql: "{% for row in outputs.fetch.rows %} INSERT INTO pl_store_distribute (year_month,store_code, update_date) values ({{row.play_time}}, {{row.concert_id}}, TO_TIMESTAMP('{{row.timestamp_type}}', 'YYYY-MM-DDTHH:MI:SS.US') ); {% endfor %}"
Properties
sql *Requiredstring
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
url *Requiredstring
The JDBC URL to connect to the database
afterSQL string
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
connectionPoolSize integerstring
10Maximum 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.
connectionPooling booleanstring
trueReuse 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.
fetchSize integerstring
10000Number 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
fetchType string
NONESTOREFETCHFETCH_ONENONEResult 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
outputFiles array
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.
parameters object
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
password string
The database user's password
pluginDefaultsRef Non-dynamicstring
Reference (ref) of the pluginDefaults to apply to this task.
ssl booleanstring
falseIs the connection SSL?
sslCert string
The SSL cert
Must be a PEM encoded certificate
sslKey string
The SSL key
Must be a PEM encoded key
sslKeyPassword string
The SSL key password
sslMode string
DISABLEALLOWPREFERREQUIREVERIFY_CAVERIFY_FULLThe SSL mode
sslRootCert string
The SSL root cert
Must be a PEM encoded certificate
timeZoneId string
The time zone id to use for date/time manipulation. Default value is the worker's default time zone id
username string
The database user
Outputs
row object
First row of fetched data
Only populated when fetchType is FETCH_ONE
rows array
List of all fetched rows
Only populated when fetchType is FETCH
size integer
Number of rows fetched
Only populated when fetchType is FETCH or STORE
uri string
uriURI of stored results in internal storage
Only populated when fetchType is STORE; file is stored in internal storage using ION format
Metrics
fetch.size counter
rowsThe number of fetched rows.