TimescaleDB SQL
Type:
postgres_sql
• Category:flow
• Tags:sql
,postgres
,timescale
,data
Description
Execute advanced SQL against TimescaleDB
Parameters
Name | Type | Description | Required | Default |
---|---|---|---|---|
sql | code | SQL query | no |
Help
Overview
The TimescaleDB SQL Worker is a specialized component designed to run sophisticated SQL statements directly against a TimescaleDB instance. It enables analysts and developers to perform high‑performance time‑series queries, complex joins, aggregations, and window functions without leaving the workflow. By encapsulating the execution logic, the worker abstracts connection handling, query submission, and result retrieval, allowing downstream tasks to focus on interpreting the data rather than managing database interactions.
Inputs
sql
(code
) – A string containing a complete, syntactically valid SQL query.- The query may reference any table, view, or materialized view that exists in the target TimescaleDB database.
- It can include standard SQL constructs as well as TimescaleDB‑specific extensions such as hypertable functions, time‑bucket aggregations, and continuous aggregates.
- The worker expects the query to be self‑contained; any required parameters should be embedded directly or supplied through prepared statements prior to execution.
Minimal Example Usage
Assume you have a hypertable named market_data
that stores tick‑level price information with columns time
, symbol
, and price
. To retrieve the average price for each symbol over the last hour, you could supply the following input to the worker:
-
sql
SELECT
symbol,
AVG(price) AS avg_price
FROM market_data
WHERE time >= now() - interval '1 hour'
GROUP BY symbol
ORDER BY avg_price DESC;
When the worker receives this query, it connects to the configured TimescaleDB instance, executes the statement, and returns the result set as a structured table (e.g., JSON or CSV, depending on downstream handling). The consumer can then use the returned data for reporting, visualization, or further analytical processing.