Skip to main content

Wait Row

Waits until a new row is inserted into a specified table. This node blocks execution until new data is detected.

Common Properties

  • Name - The custom name of the node.
  • Color - The custom color of the node.
  • Delay Before (sec) - Waits in seconds before executing the node.
  • Delay After (sec) - Waits in seconds after executing node.
  • Continue On Error - Automation will continue regardless of any error. The default value is false.
info

If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.

Inputs

  • Connection Id - The unique identifier of the database connection to use (optional if credentials provided directly).
  • Table Name - The name of the table to monitor for new rows.
  • Sort By - The column name to sort by for detecting new rows. Typically an auto-increment ID or timestamp column.

Options

  • Poll Time (s) - Time interval in seconds between checks for new rows. Default: 1.0 second.
  • Credentials - MySQL database credentials (optional). Use this if you want to wait without a Connect node.
  • Parameters - Additional connection string parameters (optional). Only used when credentials are provided.

Output

  • None - The node completes when a new row is detected.

How It Works

The Wait Row node monitors a table for new rows. When executed, the node:

  1. Retrieves the database connection (either from connection ID or creates new connection from credentials)
  2. Validates the table name and sort column are not empty
  3. Constructs a query to get the latest value from the sort column: SELECT {sortBy} FROM {table} ORDER BY {sortBy} DESC LIMIT 1
  4. On first check, records the latest value (baseline)
  5. Polls the table at the specified interval
  6. Compares the latest value with the baseline
  7. Continues execution when a new higher value is detected (new row inserted)
  8. Blocks the flow until the condition is met

Requirements

  • Either: A valid connection ID from Connect node OR valid database credentials
  • Valid table name that exists in the database
  • Valid sort column name that exists in the table
  • Sort column should be sequential (auto-increment, timestamp, sequential number)
  • Database user must have SELECT permission on the table
  • Active database connection during the wait period

Error Handling

The node will return specific errors in the following cases:

  • ErrInvalidArg - Table name is empty or Sort By column is empty
  • ErrNotFound - Connection ID not found

Sort Column Requirements

The Sort By column should be:

  • Sequential - Values increase for newer rows
  • Sortable - Comparable values (numbers, dates, timestamps)
  • Non-decreasing - New rows have equal or greater values

Good Sort Columns

  • id (auto-increment INT)
  • created_at (TIMESTAMP, DATETIME)
  • order_number (sequential INT)
  • log_id (auto-increment BIGINT)
  • timestamp (UNIX timestamp)

Avoid These Columns

  • Non-sequential columns (random UUIDs)
  • Columns that can decrease (balance, quantity)
  • Columns that might be null
  • Columns that aren't updated on insert

Usage Examples

Wait for New Order

Connect

Wait Row
- Table Name: orders
- Sort By: order_id
- Poll Time: 2.0

Query (get latest order)
- SELECT * FROM orders ORDER BY order_id DESC LIMIT 1

Process Order

Disconnect

Monitor Log Table

Connect

Loop (continuous monitoring)

Wait Row
- Table Name: application_logs
- Sort By: log_id
- Poll Time: 1.0

Query (get new logs)

Process Logs

Send Alerts if needed

Real-Time Data Processing

Connect

Wait Row (wait for sensor data)
- Table Name: sensor_readings
- Sort By: reading_timestamp
- Poll Time: 0.5

Query (get latest reading)

JavaScript (analyze reading)

If (threshold exceeded)
└─ Send Alert

Disconnect

Common Use Cases

  1. Order Processing - Wait for new orders and process them
  2. Log Monitoring - Monitor application logs for new entries
  3. Real-Time Data - React to new sensor data or measurements
  4. Notification System - Wait for new notification requests
  5. Queue Processing - Process items as they're added to a queue table
  6. Audit Monitoring - Watch for new audit log entries
  7. Data Integration - React to data added by external systems
  8. Event-Driven Automation - Trigger workflows when new rows appear

Polling Behavior

Initial Baseline

On the first check:

  1. Queries for the latest row: SELECT {sortBy} FROM {table} ORDER BY {sortBy} DESC LIMIT 1
  2. Stores the value as the baseline
  3. Continues polling

Empty Table

If the table is empty on first check:

  1. Sets baseline to empty
  2. Continues polling
  3. Triggers when the first row is inserted

Subsequent Checks

On each poll:

  1. Queries for the latest row value
  2. Compares with baseline using string comparison
  3. If new value is greater than baseline → new row detected → node completes
  4. If new value is less than or equal to baseline → continues polling
  5. Updates baseline to latest value

Poll Interval

The Poll Time option controls check frequency:

  • Lower values (0.5s) - More responsive but higher database load
  • Higher values (5s) - Less database load but slower to detect

Tips for Effective Use

  • Choose Right Sort Column - Use auto-increment ID or timestamp
  • Poll Time Balance - Balance responsiveness vs database load
  • Index Sort Column - Ensure sort column is indexed for performance
  • Connection Stability - Maintain stable connection during wait
  • Timeout Strategy - Implement timeout for cases where rows might not arrive
  • Empty Table Handling - Consider what happens if table is initially empty
  • Multiple Row Detection - Node triggers on ANY new row, not just one

Best Practices

With Timeout

Connect

Parallel
├─ Wait Row (wait for new data)
│ - Table Name: incoming_data
│ - Sort By: created_at
└─ Delay (timeout after 10 minutes)
- Delay: 600 seconds

If (Wait Row completed first)
└─ Process new data
Else
└─ Log timeout and continue

Disconnect

Process Latest Row

Wait Row
- Table Name: orders
- Sort By: order_id

Query (get the new row)
- SELECT * FROM orders
ORDER BY order_id DESC
LIMIT 1

Process Order Data

Continuous Monitoring

Connect

Loop (infinite)

Wait Row
- Table Name: events
- Sort By: event_timestamp
- Poll Time: 1.0

Query (get all new events since last check)

Process Each Event

Update baseline

Queue Processing Pattern

Connect

Loop

Wait Row (wait for new job)
- Table Name: job_queue
- Sort By: created_at

Query (get oldest unprocessed job)
- SELECT * FROM job_queue
WHERE status = 'pending'
ORDER BY created_at ASC
LIMIT 1
FOR UPDATE

Process Job

Non Query (update job status)
- UPDATE job_queue
SET status = 'completed'
WHERE job_id = {{jobId}}

Multi-Table Monitoring

Parallel
├─ Wait Row (monitor orders)
│ - Table: orders, Sort By: order_id
├─ Wait Row (monitor payments)
│ - Table: payments, Sort By: payment_id
└─ Wait Row (monitor shipments)
- Table: shipments, Sort By: shipment_id

Process whichever triggers first

Performance Considerations

  • Index on Sort Column - CREATE INDEX idx_sortcol ON table(sort_column)
  • Poll Frequency - More frequent polling increases database load
  • Query Optimization - ORDER BY with LIMIT 1 should use index
  • Connection Pooling - Keep connection open to avoid overhead
  • Table Size - Performance degrades with very large tables if not indexed

Optimize Query Performance

Ensure the sort column has an index:

-- Check for index
SHOW INDEX FROM orders WHERE Column_name = 'order_id';

-- Create index if needed
CREATE INDEX idx_order_id ON orders(order_id);

Common Errors and Solutions

Table Name Cannot Be Empty

Error: ErrInvalidArg: Table name cannot be empty

Solutions:

  • Provide a valid table name
  • Ensure the variable containing the table name has a value

Sort By Column Cannot Be Empty

Error: ErrInvalidArg: Sort By column cannot be empty

Solutions:

  • Provide a valid column name for Sort By
  • Typically use 'id' or 'created_at'
  • Ensure the variable has a value

Connection Not Found

Error: ErrNotFound: Connection not found

Solutions:

  • Ensure Connect node runs before Wait Row
  • Verify connection ID is correct
  • Or use Credentials option to connect directly

Infinite Wait

Issue: Node waits indefinitely if no rows are inserted

Solutions:

  • Implement timeout using Parallel node with Delay
  • Add maximum wait time logic
  • Verify external system is actually inserting rows

Wrong Sort Column

Issue: Node doesn't trigger even when rows are added

Solutions:

  • Verify sort column is sequential (auto-increment or timestamp)
  • Check column name is correct (case-sensitive)
  • Ensure new rows have increasing values in sort column
  • Test with: SELECT {sortBy} FROM {table} ORDER BY {sortBy} DESC LIMIT 5

Advanced Examples

Get All New Rows

Wait Row (detect new row)

JavaScript (store current max ID)
const maxId = await query('SELECT MAX(id) FROM table');

Wait Row (wait for next row)

Query (get all new rows)
- SELECT * FROM table
WHERE id > {{previousMaxId}}
ORDER BY id ASC

Process all new rows

Real-Time Alert System

Connect

Loop (continuous monitoring)

Wait Row
- Table Name: alerts
- Sort By: alert_timestamp
- Poll Time: 0.5

Query (get latest alert)
- SELECT * FROM alerts
ORDER BY alert_timestamp DESC
LIMIT 1

JavaScript (evaluate alert severity)

If (severity = 'critical')
├─ Send SMS
└─ Send Email
Else If (severity = 'high')
└─ Send Email
Else
└─ Log Only

Data Synchronization

Source Database:
Insert new data → triggers Wait Row in sync flow

Sync Flow:
Connect (to source DB)

Wait Row
- Table Name: source_table
- Sort By: updated_at

Query (get new/updated records)
- SELECT * FROM source_table
WHERE updated_at > {{lastSync}}

Connect (to destination DB)

Insert Table (sync data)

Disconnect both

Event Stream Processing

Connect

Loop

Wait Row (wait for event)
- Table Name: event_stream
- Sort By: event_id
- Poll Time: 1.0

Query (get event details)

JavaScript (route based on event type)

Switch (event type)
├─ Case 'order': Process Order
├─ Case 'payment': Process Payment
├─ Case 'shipment': Process Shipment
└─ Default: Log Unknown Event

Comparison with Alternatives

Wait Row vs Polling Loop

Wait Row:

Wait Row (built-in polling)
- Simpler, automatic polling

Manual Polling:

Loop
Query (check for new rows)
If (new rows found) → Break
Delay
Continue

Wait Row vs Trigger

Wait Row:

  • Polls the database periodically
  • No database trigger needed
  • Works with any table
  • Configurable poll interval

Database Trigger:

  • Event-driven (immediate)
  • Requires trigger creation
  • More complex setup
  • Lower latency

Working with Timestamps

Timestamp Column

Wait Row
- Table Name: events
- Sort By: created_at

The created_at column should be:

created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP

Or:

created_at DATETIME DEFAULT CURRENT_TIMESTAMP

UNIX Timestamp

Wait Row
- Table Name: logs
- Sort By: timestamp

With:

timestamp BIGINT -- UNIX timestamp

See Also