{"library":"node-red-contrib-postgresql","title":"PostgreSQL Node for Node-RED","description":"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.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install node-red-contrib-postgresql"],"cli":null},"imports":["Install 'node-red-contrib-postgresql' via Node-RED palette manager.","// In a preceding Function node:\nmsg.query = 'SELECT * FROM my_table WHERE id = $1';","// In a preceding Function node:\nmsg.params = [msg.payload.id];"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"/* This is a Node-RED Function node preparing a message for the PostgreSQL node */\n\n// Example 1: Dynamic SQL query\n// msg.query = 'SELECT * FROM users WHERE status = $1';\n// msg.params = ['active'];\n\n// Example 2: Insert data with parameterized query\nconst userId = 'user_' + Date.now();\nconst username = 'testuser_' + Math.floor(Math.random() * 1000);\nconst email = `${username}@example.com`;\n\nmsg.query = `\n  INSERT INTO public.users (id, username, email, created_at)\n  VALUES ($1, $2, $3, NOW())\n  ON CONFLICT (id) DO UPDATE SET\n  username = EXCLUDED.username, email = EXCLUDED.email;\n`;\nmsg.params = [userId, username, email];\n\n// Example 3: Select data by ID using named parameters (less robust, prefer numeric)\n// msg.query = 'SELECT * FROM products WHERE id = $productId;';\n// msg.queryParameters = { productId: 123 };\n\nreturn msg;","lang":"javascript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}