QANode Logo

PostgreSQL Node

The PostgreSQL node allows you to execute queries and operations on a PostgreSQL database. It offers both a visual query builder and the option to write custom SQL.


Overview

PropertyValue
Typepostgres-query
CategoryDatabase
Color🟢 Green (#22c55e)
Inputin
Outputout

Connection

Using Saved Credentials (Recommended)

Select a credential of type PostgreSQL in the Credential field. The credential contains all connection information.

Manual Configuration

FieldTypeDescription
Connection StringstringFull URI (alternative)
HoststringServer address
PortnumberPort (default: 5432)
DatabasestringDatabase name
UserstringConnection user
PasswordstringConnection password
SSLbooleanUse SSL connection

Connection String:

postgresql://user:password@host:5432/database?sslmode=require

Query Modes (Presets)

Custom SQL

Write SQL freely with parameter support.

FieldTypeDescription
SQLstringSQL query (supports {{ }})
ParametersarrayValues for $1, $2, etc. placeholders

Example:

SELECT * FROM users WHERE email = $1 AND active = $2

Parameters: ["john@example.com", true]

Security: Always use parameters ($1, $2) instead of concatenating values directly in SQL. This prevents SQL injection.


SELECT (Visual Builder)

Build SELECT queries without writing SQL:

FieldTypeDescription
TablestringSource table
ColumnsarrayColumns to select (empty = all)
WHERE ConditionsarrayFilters
ORDER BYobjectColumn and sort direction
LIMITnumberRecord limit

WHERE Conditions:

FieldOperatorValue
email=john@example.com
age>18
nameLIKE%Smith%

EXISTS

Checks whether at least one record matching the criteria exists.

FieldTypeDescription
TablestringTable
WHERE ConditionsarraySearch criteria

Returns rowCount: 1 if it exists, rowCount: 0 if it does not exist.


COUNT

Counts records matching the criteria.

FieldTypeDescription
TablestringTable
WHERE ConditionsarrayCount criteria

ASSERT

Checks whether a value in the database matches the expected value. Ideal for data validations.

FieldTypeDescription
TablestringTable
ColumnstringColumn to check
OperatorstringComparison operation
ValuestringExpected value
WHERE ConditionsarrayFilters to locate the record

INSERT

Inserts new records.

FieldTypeDescription
TablestringTarget table
ValuesarrayColumn-value pairs

Example:

ColumnValue
nameMaria
emailmaria@example.com
activetrue

UPDATE

Updates existing records.

FieldTypeDescription
TablestringTable
SetsarrayColumn-value pairs to update
WHERE ConditionsarrayFilters

DELETE

Removes records.

FieldTypeDescription
TablestringTable
WHERE ConditionsarrayFilters (required for safety)

Outputs

OutputTypeDescription
rowsarrayArray of returned records
rowCountnumberNumber of affected/returned records

Accessing Outputs

// All records
{{ steps.query.outputs.rows }}

// First record
{{ steps.query.outputs.rows[0] }}

// Specific field from the first record
{{ steps.query.outputs.rows[0].name }}  →  "John"
{{ steps.query.outputs.rows[0].email }}  →  "john@example.com"

// Count
{{ steps.query.outputs.rowCount }}  →  5

Practical Examples

Validate data after creation via API

[HTTP Request: POST /api/users → body: { "name": "John" }]
    │
    â–¼
[PostgreSQL: SELECT * FROM users WHERE name = 'John']
    │
    â–¼
[If: {{ steps.query.outputs.rowCount }} > 0]
    │ true → [Log: "User successfully created in the database"]
    │ false → [Stop and Fail]

Prepare data for testing

[PostgreSQL: INSERT INTO test_data (key, value) VALUES ('token', 'abc123')]
    │
    â–¼
[HTTP Request: GET /api/verify?token={{ steps.insert.outputs.rows[0].token }}]

Clean up data after testing

[... tests ...]
    │
    â–¼
[PostgreSQL: DELETE FROM test_data WHERE created_by = 'automated-test']

Tips

  • Use saved credentials to manage connections in a centralized way
  • Use parameters ($1, $2) in custom SQL to prevent SQL injection
  • The visual query builder is ideal for simple operations and is less prone to syntax errors
  • Use expressions in values: {{ steps.api.outputs.json.id }} to use data from previous nodes
  • Test the connection before running the flow using the test button on the credentials screen