PERFORM

Executes a query and discards the result (side-effects only).

Category: dynamic-sql

Syntax

PERFORM <query>;

Description

## Overview PERFORM executes a SQL query for its side effects (such as calling functions or checking for row existence) and discards the result set. It is the PL/pgSQL equivalent of running a SELECT when you do not need the returned data. ## Behavior - The query text provided after PERFORM is treated as the body of a SELECT statement. The executor automatically prepends `SELECT ` before execution. - Any PL/pgSQL variable references in the query text are resolved via the SqlResolver before execution, substituting current variable values. - The query executes through DeltaForge's routed SQL execution engine. The result batches are discarded after execution. - The FOUND implicit variable is updated based on whether the query returned any rows. This makes PERFORM useful for existence checks. - PERFORM does not support INTO. To capture results, use a regular SELECT...INTO statement or EXECUTE...INTO. ## Differences from PostgreSQL - Behavior is consistent with PostgreSQL PL/pgSQL. The PERFORM keyword is replaced with SELECT internally, and results are discarded. - Variable resolution uses DeltaForge's SqlResolver, which performs textual substitution. PostgreSQL uses a different internal mechanism for variable binding.

Parameters

NameTypeDescription
queryProvide the query body (without the SELECT keyword). The executor prepends SELECT automatically.

Examples

DO $$
BEGIN
  PERFORM 1 FROM employees WHERE id = 42;
  IF FOUND THEN
    PRINT 'Employee 42 exists';
  ELSE
    PRINT 'Employee 42 not found';
  END IF;
END;
$$;
DO $$
DECLARE
  rec RECORD;
BEGIN
  FOR rec IN SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' LOOP
    PERFORM 1 FROM information_schema.columns WHERE table_name = rec.table_name AND column_name = 'updated_at';
    IF FOUND THEN
      PRINT rec.table_name, 'has updated_at column';
    END IF;
  END LOOP;
END;
$$;
DO $$
BEGIN
  PERFORM set_config('app.current_user', 'pipeline_runner', true);
  PRINT 'Config set';
END;
$$;
DO $$
DECLARE
  order_id INT := 1001;
BEGIN
  PERFORM 1 FROM orders WHERE id = order_id AND status = 'shipped';
  IF NOT FOUND THEN
    RAISE EXCEPTION 'Order % is not shipped', order_id;
  END IF;
END;
$$;

Pitfalls

See Also

Open in interactive docs →   DeltaForge home →