Skip to main content

Query Database

Controlled node

Overview

The Query Database node executes raw SQL queries against project databases. This node provides direct access to the underlying PostgreSQL database, enabling complex data retrieval, aggregation, and manipulation operations that go beyond standard CRUD operations.

The node includes security validations to prevent resource limit modifications and accepts standard PostgreSQL SQL syntax. Results are returned as an array of objects representing the queried rows.

Security Restrictions

For security and resource management, the node blocks queries containing certain PostgreSQL configuration parameters including statement_timeout, work_mem, maintenance_work_mem, and temp_file_limit. Queries attempting to modify these settings will return an error.

Inputs

InputTypeDescriptionDefault
RunEventFires when the node starts executing the query.-
Database IDDataThe unique identifier of the project database to query. Can be selected via the panel UI or provided as an input.-
QueryDataThe SQL query string to execute. Supports standard PostgreSQL syntax including SELECT, JOIN, WHERE, GROUP BY, and aggregate functions.-

Outputs

OutputTypeDescription
ResultDataContains an array of row objects matching the query results, or an error object if the query failed.
DoneEventFires when the query execution completes, regardless of success or failure.

Runtime Behavior and Defaults

When triggered by the Run event, the node validates that both the Database ID and Query inputs are valid strings. If validation passes, it executes the SQL query against the specified database using the project's database connection pool.

The node performs the following validations:

  • Ensures the query is a string type
  • Blocks dangerous SQL parameters that could modify resource limits
  • Verifies the database ID exists and is accessible within the project context

If validation fails or the query execution errors, the Result output will contain an error object with a descriptive message. On success, Result contains the query results as an array of objects.

Default Values:

  • No default query is provided (empty string)
  • No default database is selected

Example

Connect a Start node's fired output to the Run input of the Query Database node. In the panel UI, select a database from your project and enter a SQL query:

SELECT id, name, email 
FROM users
WHERE created_at > '2024-01-01'
ORDER BY name ASC
LIMIT 100

Connect the Result output to a Show node to inspect the returned data, or use the Done event to trigger subsequent nodes after the query completes.