Skip to main content
Version: v9

SQL Query

The SQL Node executes SQL queries against databases (MariaDB, Microsoft SQL Server, MySQL, PostgreSQL), optionally storing query results in a Variable for further processing in your Flow.

SQL Config​

  • SQL Config picks the database connection. The list holds the connections from Robot Configuration → SQL Connections, where the database type, host, port, credentials and database name are set and where you can test the connection.
  • Add SQL Config at the end of the list creates "New SQL Config" (PostgreSQL, localhost, port 5432), selects it and opens the Robot Configuration on the SQL Connections tab to complete it.
  • Without a selection the Node is Not configured: "Please select a SQL config or create a new one".
  • The database host must be reachable from the Robot CU where RobFlow is running.

SQL Query​

Enter the query in SQL Query. It is an Expression field: insert a Variable with # and its current value is inserted into the query as text when the Node runs. Put quotes around it where SQL expects a string. The field is required. The SQL Node supports SELECT, INSERT, UPDATE and DELETE:

  • SELECT: Retrieve data from tables (e.g., SELECT * FROM inventory WHERE id = 25)
  • INSERT: Add new records (e.g., INSERT INTO inventory (name, quantity) VALUES ('Cogs', '10'))
  • UPDATE: Modify existing records (e.g., UPDATE inventory SET quantity = 15 WHERE name = 'Cogs')
  • DELETE: Remove records (e.g., DELETE FROM inventory WHERE id = 5)

Store Query Result​

Tick Store Query Result to keep the result of a SELECT query. Result Variable (String Variables only) receives the rows as a JSON array of objects, one per row. Result Processing is pre-filled with the Result Variable; add bracket notation to keep only part of it. If the query returns no rows, the Variable is left unchanged. With the box ticked and no Result Variable, the Node is Not configured: "Result Variable is required when storing result".

Result Processing​

Query results are automatically converted to JSON format. You can narrow down what you store in the Variable by specifying a specific part of the JSON response using bracket notation.

Example: queryResult[0]["name"]​

  • queryResult: The Variable to store the query results in (should match the previously selected Result Variable)
  • [0]: First row in the query result array
  • ["name"]: The name column value from that row

Node Outputs​

The SQL Node has two outputs for Flow control:

  • Success: Triggered when the query executes successfully.
  • Failure: Triggered when the DB connection or the query fails (Connection or auth issues, syntax errors, constraint violations, etc.).

Example Usage​

Fetching data from a database

  • SQL Config: Inventory DB (a PostgreSQL connection in SQL Connections)
  • Query: SELECT * FROM inventory WHERE id = 42
  • Result Variable: inventoryList
  • Result Processing: inventoryList[0]["quantity"] (Stores the quantity value of the first row returned from the query to the selected Variable)

Inserting data into a database

  • SQL Config: Warehouse DB (a MySQL connection in SQL Connections)
  • Query: INSERT INTO products (name, price, stock) VALUES ('BoltA5', 19.99, 100)

Tips​

  • Connect to the database with a user with minimal required permissions (e.g., read-only for SELECT queries).
  • Be mindful when using queries that modify data in your database (INSERT, UPDATE, DELETE) as these changes are permanent.
  • Test your SQL query in a database client before using it in the SQL Node.
  • Use Result Processing to extract only the data you need, reducing Variable size.
  • Query results are automatically converted from database-specific types (DECIMAL, DATETIME) to JSON-compatible formats.
  • A failed query or connection is written to the Message Log, with the database's error, before the Flow continues on Failure.
  • Use the Success/Failure outputs to handle errors gracefully (Ex. retry logic or error notifications).
  • Database connections are automatically closed after query execution to prevent resource leaks.