Script node
What it does
The Script node runs a DuckDB SQL query over the rows that reach it and sends the query's result downstream. The incoming rows are a table named input.
Scripts run in DuckDB SQL. For work that SQL does not suit, use a Transform or Compute node.
The Script node is turned on per account. If Script is not in your palette, the account Owner emails DataLug support at support@datalug.io.
When to use
- The work is set-based and awkward to build from other nodes: window functions, ranking, running totals, pivots, custom parsing with SQL functions.
- You already have the logic as a SQL query.
- The work only needs the incoming rows. A script cannot reach a network, a file system or another database. To query a database, use a Source node.
Configure
Select the node and press Configure in the side panel to open Configure Script. Save keeps the dialog open, Done saves and closes it, and Cancel discards the changes since the last save. A message confirms each save.
Language, limits and libraries
- Language:
DuckDB SQL. - Timeout (ms): from 1,000 to 300,000. The default is 30,000. The platform limit applies when it is lower than this value.
Script
- The editor completes upstream field names. Press
Ctrl+Spaceto open the list. - Fields on input lists the columns of the
inputtable, with their types. - Examples holds ready-made queries. Pick one to preview it, then insert it.
Input and output schema
- Output schema: the columns the query returns, as name and type (
string,number,boolean,date,json). Downstream nodes see these columns before the flow runs.
Preview and validate
- Validate script checks the script for statements that are not allowed.
- Run preview runs your SQL against the node's sample rows. No run is created and nothing is saved.
| Preview result | Meaning |
|---|---|
| Rows | The query ran. The first rows are shown. |
Write a SELECT in the editor, then preview it. | The editor is empty. |
Add at least one sample row. | The input table takes its columns from the sample rows. |
| A database error | The query did not run. The message is DuckDB's own. |
The runtime for this project's environment cannot be reached. | The preview runs on the project's own runtime, which is not answering. |
Previews cannot run on the agent for this project's environment. | The project runs on a Private Agent that polls for work. Previews are not available there. |
Ports
| Port | Direction | Kind | Notes |
|---|---|---|---|
in | in | data | Rows to query, as the input table. |
out | out | data | The rows the query returned. |
error | out | control | Receives the input rows when the script fails or exceeds its timeout or row limit. |
The query runs once all input rows have arrived, so out sends its rows after the last input chunk.
Examples
Latest order per customer.
SELECT *
FROM input
QUALIFY ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY order_date DESC) = 1
Running total.
SELECT *, SUM(amount) OVER (ORDER BY order_date) AS running_total
FROM input
Split a delimited column.
SELECT id, UNNEST(STRING_SPLIT(tags, ',')) AS tag
FROM input
Troubleshooting
| Symptom | Cause | What to do |
|---|---|---|
Script node has no SQL to run. Write a SELECT in the editor. | The editor is empty. | Write a query. |
| The run fails with a timeout | The query ran longer than the timeout. | Simplify the query, or filter rows earlier in the flow. |
| A column is not found | The column name differs from the upstream field. | Check Fields on input for the exact name. |
| Downstream nodes do not see the new columns | The output schema is empty or out of date. | Add the columns under Output schema. |