SQLSTATE 42601 ERROR Class 42: Syntax Error or Access Rule Violation

syntax_error query has no destination for result data — 42601

PostgreSQL error "query has no destination for result data" (SQLSTATE 42601): what it means, common causes, and how to fix it.

PG 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed May 2025 Grounded in source

Diagnostic Queries

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).

  • A SELECT in PL/pgSQL has nowhere to send its results.
  • Common when a bare SELECT is used instead of PERFORM.
  • The hint suggests using PERFORM instead.

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

  • Writing SELECT …; instead of PERFORM …; to run for side effects.
  • Forgetting INTO when capturing a single-row result.
  • Forgetting RETURN QUERY in a set-returning function.

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”.

Was this helpful?