Assignment (:=)

Assigns a value to a variable, record field, or array element.

Category: control-flow

Syntax

<target> := <expression>;

Targets: variable, record.field, array[subscript]

Description

## Overview The assignment operator `:=` sets a variable, record field, or array element to the result of an evaluated expression. The right-hand side is evaluated first, then the result is stored in the target. ## Behavior - The expression on the right is evaluated using the DataFusion expression evaluator, which supports arithmetic, string concatenation, function calls, and subqueries. - For simple variables, the new value must be implicitly coercible to the declared type. DeltaForge applies automatic type normalization (for example, Utf8View to Utf8) after evaluation. - Record field assignments (e.g., `rec.field := value`) create the field dynamically if it does not already exist on the record. - Array element assignments use 1-based subscripts, consistent with PostgreSQL convention. - Assignment never returns a value; control flow always continues to the next statement. ## Differences from PostgreSQL - DeltaForge uses Arrow/DataFusion scalar types internally. Some implicit casts that work in PostgreSQL (e.g., assigning a numeric string to an integer) may require explicit casting via `::INT`. - The `=` operator is not accepted as an assignment operator. Only `:=` is valid in assignment context, matching the PL/pgSQL standard.

Examples

DO $$
DECLARE
  counter INT := 0;
BEGIN
  counter := counter + 1;
  PRINT counter;
END;
$$;
DO $$
DECLARE
  emp RECORD;
BEGIN
  emp.name := 'Alice';
  emp.dept := 'Engineering';
  PRINT emp.name, emp.dept;
END;
$$;
DO $$
DECLARE
  scores INT[] := ARRAY[10, 20, 30];
BEGIN
  scores[2] := 99;
  PRINT scores[2];
END;
$$;
DO $$
DECLARE
  total NUMERIC := 0;
  row_count INT;
BEGIN
  SELECT count(*), sum(amount) INTO row_count, total FROM orders;
  PRINT 'Rows:', row_count, 'Total:', total;
END;
$$;
DO $$
DECLARE
  label TEXT;
BEGIN
  label := 'Pipeline run at ' || now()::TEXT;
  PRINT label;
END;
$$;

Pitfalls

See Also

Open in interactive docs →   DeltaForge home →