Registry / database / node-red-contrib-postgresql

node-red-contrib-postgresql

JSON →
library0.15.4jsnpmunverified

node-red-contrib-postgresql is a Node-RED contribution that provides a node for interacting with PostgreSQL databases. It is currently at version 0.15.4 and has a relatively steady release cadence, primarily focused on bug fixes, dependency updates, and minor enhancements. Key features include robust support for parameterized SQL queries (both numeric $1/$2 and emulated named $id parameters), efficient handling of large datasets through resultset splitting and backpressure (flow control), and flexible dynamic SQL query input via `msg.query`. It provides database responses in `msg.payload`, with additional metadata in `msg.pgsql`. The node integrates directly into the Node-RED flow editor, abstracting away direct `node-postgres` client management for most use cases, though advanced users can dynamically configure client settings via `msg.pgConfig` for specific scenarios.

npm install node-red-contrib-postgresql
INSTALL
IMPORT
SIG · NODE-RED-CONTRIB-P
N
node-red-contrib-postgresql
databasejavascriptv0.15.4
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

PostgreSQL Node (Conceptual)
Install 'node-red-contrib-postgresql' via Node-RED palette manager.
import { PostgresqlNode } from 'node-red-contrib-postgresql';
This package is a Node-RED contribution; its primary 'import' is installation via the Node-RED editor's palette manager. It is not designed for direct JavaScript `import` or `require` in application code.
msg.query for Dynamic SQL
// In a preceding Function node: msg.query = 'SELECT * FROM my_table WHERE id = $1';
import { query } from 'node-red-contrib-postgresql';
This refers to the `msg.query` property, which is used to pass a dynamic SQL query string to the PostgreSQL node from an upstream Node-RED message.
msg.params for Parameterized Queries
// In a preceding Function node: msg.params = [msg.payload.id];
import { params } from 'node-red-contrib-postgresql';
This refers to the `msg.params` property, an array used to provide parameters for numeric parameterized SQL queries (`$1`, `$2`, etc.) to the PostgreSQL node.

Demonstrates preparing `msg.query` and `msg.params` in a Node-RED Function node for an upsert operation into a PostgreSQL database, typically followed by the `node-red-contrib-postgresql` node.

/* This is a Node-RED Function node preparing a message for the PostgreSQL node */ // Example 1: Dynamic SQL query // msg.query = 'SELECT * FROM users WHERE status = $1'; // msg.params = ['active']; // Example 2: Insert data with parameterized query const userId = 'user_' + Date.now(); const username = 'testuser_' + Math.floor(Math.random() * 1000); const email = `${username}@example.com`; msg.query = ` INSERT INTO public.users (id, username, email, created_at) VALUES ($1, $2, $3, NOW()) ON CONFLICT (id) DO UPDATE SET username = EXCLUDED.username, email = EXCLUDED.email; `; msg.params = [userId, username, email]; // Example 3: Select data by ID using named parameters (less robust, prefer numeric) // msg.query = 'SELECT * FROM products WHERE id = $productId;'; // msg.queryParameters = { productId: 123 }; return msg;
Debug
Known issues
gotchaNamed parameters (e.g., `$id` in queries with `msg.queryParameters`) are emulated by this library and not natively supported by PostgreSQL. This emulation can be less robust than standard numeric parameters (`$1`, `$2`).
fix
Prefer numeric parameterized queries (`$1`, `$2`, etc.) with `msg.params` for enhanced robustness and direct PostgreSQL compatibility, especially for critical applications.
affects: >=0.1.0
gotchaProviding dynamic connection parameters via `msg.pgConfig` for each message bypasses the internal connection pooling mechanism of the Node-RED node. This can lead to decreased performance and resource inefficiency compared to using the persistent configuration node.
fix
For most scenarios, configure your PostgreSQL database connection using the dedicated configuration node within the Node-RED editor to benefit from connection pooling and optimized resource management.
affects: >=0.1.0
gotchaWhen the 'Split results' option is enabled and 'Number of rows per message' is set to 1, the `msg.payload` output will contain a single-row object directly, rather than the typical array of objects.
fix
Downstream nodes processing the output should be designed to handle both array and single-object payloads or explicitly check `msg.payload`'s type when the 'Split results' option is active.
affects: >=0.1.0
breakingDirectly embedding user-supplied values into SQL query templates using Mustache (e.g., `{{{msg.id}}}`) can introduce SQL injection vulnerabilities if inputs are not properly sanitized.
fix
Always use parameterized queries with `msg.params` or `msg.queryParameters` for any user-controlled input. This separates data from the query, preventing injection attacks.
affects: >=0.1.0
breakingVersions prior to `0.15.3` contained a bug that could lead to `pg-cursor` exceptions, particularly when processing large result sets with the 'Split results' and backpressure features enabled.
fix
Upgrade to `v0.15.3` or a newer version to benefit from the fix for `pg-cursor` exceptions and ensure better stability with large datasets.
affects: <0.15.3
Errors
Common errors & fixes
TypeError: Cannot read properties of null (reading 'config')
The PostgreSQL node was deployed without being correctly linked to a valid PostgreSQL configuration node, or the configuration node was deleted or became invalid.
fix
Ensure that the PostgreSQL query node is connected to a properly configured and deployed PostgreSQL configuration node in your Node-RED flow.
syntax error at or near "..."
The SQL query provided in the node's configuration or via `msg.query` contains invalid PostgreSQL syntax, or Mustache templating was used incorrectly (e.g., missing quotes for text values).
fix
Carefully review the SQL query for any syntax errors. If using Mustache templates for text values, ensure they are correctly quoted (e.g., `WHERE name = '{{{msg.name}}}'`). Prefer parameterized queries to avoid such issues and enhance security.
Error: connect ECONNREFUSED <ip>:<port>
The Node-RED instance cannot establish a connection with the PostgreSQL database server. This often means the server is not running, is not accessible from the Node-RED host, or the connection details (host, port) are incorrect.
fix
Verify that your PostgreSQL database server is running and network accessible. Double-check the host IP address/hostname and port number in your PostgreSQL configuration node.
Error: password authentication failed for user "..."
The username or password provided in the PostgreSQL connection configuration is incorrect or lacks the necessary permissions to connect to the specified database.
fix
Confirm that the username and password configured in the PostgreSQL connection node are correct and that the user has appropriate database access privileges.
Upgrade
Version history
0.15.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources