Postgres

postgres

This project demonstrates how to execute basic PostgreSQL queries from Node-RED.

Services Used

  • PostgreSQL database – Used to store and query data

List of used nodes

  • Inject/Timestamp – Triggers the flow

  • Function – Adds custom JavaScript logic

  • Debug – Outputs messages to the debug console

  • PostgreSQL node – Executes SQL queries provided via the msg.query property

For more information, refer to the official Node-RED documentation. (TODO: Add link)

GROUP: table queries

group table queries

This group demonstrates basic PostgreSQL operations, such as creating a table and inserting data. Each operation can be triggered by clicking the button next to the Inject node. The PostgreSQL node executes the SQL passed through the msg.query property.

PostgreSQL node configuration:

gui postgres config

The host is set to the Podman container name. If running in a Pod environment, use the loopback address 127.0.0.1. The default database name is postgres. Authentication credentials can be set in the Security tab.

FLOW: Create table

Flow showcases how to construct and execute query for creating a table with name employees which holds several different types of data.

Example:

CREATE TABLE IF NOT EXISTS employees (
    id SERIAL PRIMARY KEY,
    first_name VARCHAR(50),
    last_name VARCHAR(50),
    email VARCHAR(100),
    department VARCHAR(50),
    salary DECIMAL
);

Other queries can be found within the implementation.