New to Kestra?
Use blueprints to kickstart your first workflows.
Run parameterised SQL queries on Postgres with Kestra. Pass the query as a flow input, secure credentials with secrets, and store all result rows.
id: postgres-query-executor
namespace: company.team
inputs:
- id: query
type: STRING
displayName: SQL Query
description: SQL statement to execute against the Postgres database
defaults: "SELECT * FROM sometable"
tasks:
- id: query_postgres
type: io.kestra.plugin.jdbc.postgresql.Queries
url: "{{ secret('POSTGRES_URL') }}"
sql: "{{ inputs.query }}"
fetchType: STORE
Execute parameterised SQL queries against a PostgreSQL database and capture the full result set as reusable data, without writing custom database scripts or scheduling cron jobs by hand. This blueprint turns an ad hoc Postgres query into a declarative, parameter-driven Kestra flow: you pass the SQL statement at runtime, the connection URL stays safe in a secret, and every returned row is stored so downstream tasks can read it. It is a building block for extractions, health checks, and reporting on top of Postgres.
query input of type STRING (default SELECT * FROM sometable) so the SQL statement is supplied at execution time instead of being hardcoded.query_postgres task (io.kestra.plugin.jdbc.postgresql.Queries) opens a JDBC connection using url: {{ secret('POSTGRES_URL') }} and runs the statement from {{ inputs.query }}.fetchType: STORE, all result rows are written to Kestra's internal storage and exposed as an output URI, ready to be consumed by later tasks or downstream flows.fetchType: STORE rather than truncated or logged.Postgres has no built-in scheduler or pipeline engine of its own (pg_cron only fires SQL on a timer, with no retries, inputs, lineage, or downstream wiring). Kestra fills that gap: drive the query from event or schedule triggers, add automatic retries on transient connection failures, track inputs and outputs as lineage across executions, and keep everything as declarative, version-controlled YAML. The stored result becomes an input to any downstream task, which raw psql or pg_cron cannot coordinate.
POSTGRES_URL: the JDBC connection URL for your Postgres database (including host, port, database, and credentials).POSTGRES_URL secret to your Kestra instance.company.team).query input.query_postgres to retrieve the result rows.Schedule or other trigger to run the query on a cadence or in response to events.