query has no destination for result data

SQLSTATE 42601 condition syntax_error class 42 — Syntax Error or Access Rule Violation severity ERROR
Reproduced & verified on PostgreSQL 14.23, 15.18, 16.14, 17.10 and 18.4 — identical message on every version.
Last reviewed 30 May 2025 · Reproduced live with the SQL on this page.

Symptoms

A PL/pgSQL function ran a query that returns rows but did not capture them (no INTO, PERFORM, or RETURN QUERY). PostgreSQL raises SQLSTATE 42601 (syntax_error).

What the server log shows

ERROR:  query has no destination for result data
HINT:  If you want to discard the results of a SELECT, use PERFORM instead.
CONTEXT:  PL/pgSQL function check_user() line 5 at SQL statement

Why PostgreSQL raises this — what the manual says

Section 41.5.2 Executing SQL Commands (PERFORM):

“One might expect that writing SELECT directly would accomplish this result, but at present the only accepted way to do it is PERFORM.”

In PL/pgSQL, a query returning rows must direct them somewhere — INTO a variable, RETURN QUERY, or be discarded via PERFORM. A plain SELECT has no destination, so PostgreSQL rejects it with 42601.

Common causes

How to fix it

  1. Use PERFORM expr; to evaluate and discard results.
  2. Use SELECT … INTO var; to capture a single-row result.
  3. Use RETURN QUERY SELECT …; to return rows from a set-returning function.

Related & next steps

Reference: PostgreSQL 18 Section 43.5 “Basic Statements”.