Skip to main content

What This Node Does

The SQL/Python node (also called the CODE node) lets you write custom code when built-in nodes don’t provide the exact transformation you need. Toggle between SQL and Python modes for advanced calculations, complex business logic, or custom data manipulation. Your code runs in a secure, sandboxed environment and operates on data from the parent node. The result becomes the output that flows to the next node.
The SQL/Python node configuration with a SQL/Python language toggle and a code editor referencing the upstream step.

When to Use This Node

Use it when:
  • A built-in node can’t do what you need (custom calculations, complex conditional logic, advanced string or date work)
  • You’re preserving existing SQL queries from another tool
  • You need pandas or numpy operations
Skip it when:
  • A built-in node (Transform, Filter, PivotTable) can do the same job faster and more clearly
  • Teammates without coding experience need to read the flow

Language Toggle

A toggle at the top switches between SQL and Python. Both operate on the same parent data:
  • SQL Mode: Standard SQL SELECT statements.
  • Python Mode: Python with pandas and numpy.

SQL Mode

The parent node’s output is available as a table named data:
If one of your source columns is also named data, bare unquoted data always refers to the parent table, not the column. Use double quotes ("data") or a table alias (FROM data AS t, then t.data) to reference it as a column instead.
You have access to standard SQL: SELECT, WHERE, CASE WHEN, GROUP BY, ORDER BY, joins, and common string, date, and math functions.

Joining Multiple Parents

When the node has more than one parent, each parent is available as a table named after its step label (shown on the node in the canvas: A1, B1, C1). The position-0 parent is also aliased as data.
Step labels update automatically if you reorder or add parents. Go Fig translates stale labels on your behalf, so your queries keep working.

Example

Creates a custom “tier” column based on revenue thresholds, filters out zero-revenue customers, and sorts by revenue.

Python Mode

The parent node’s output is available as a pandas DataFrame named data. Access columns with dot or bracket notation (data.revenue or data['Customer Name']). Three libraries are pre-imported: pandas (pd), numpy (np), and fig, Go Fig’s helper library for fuzzy matching, fiscal-year conversion, z-scores, safe percentage change, and deduplication (see Fig Helpers).

Joining Multiple Parents

Each parent is exposed as a DataFrame named after its step label (A1, B1, C1); the position-0 parent is also bound to data.

Must Return a DataFrame

Your code must return a DataFrame, not a Series or scalar. The last expression should be a DataFrame:

Example

Filters customers with revenue over $1,000, calculates a 10% commission, and returns the result.

Sandbox Restrictions

For security, code runs in an isolated sandbox: no import statements (only the pre-imported pd, np, and fig), no exec/eval/compile, no filesystem or system access, and no network requests. If you need more, preprocess your data outside Go Fig and import it as a data source.

Tips

Test with small data first: In Python, use data.head() to develop against the first few rows before running on the full dataset.
SQL vs Python: Use SQL for familiar queries and filtering. Use Python for row-wise iteration, custom functions, or pandas-specific operations.
Always use .copy() when creating filtered DataFrames in Python to avoid SettingWithCopyWarning:

Debugging

If your code isn’t behaving as expected:
  1. Check column names: data.columns (Python) or SELECT * FROM data LIMIT 5 (SQL)
  2. Check data types: data.dtypes (Python)
  3. Handle nulls: .fillna() (Python) or COALESCE() (SQL)
  4. Build incrementally: test each part before adding complexity