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 ofPERFORM …;to run for side effects. - Forgetting
INTOwhen capturing a single-row result. - Forgetting
RETURN QUERYin a set-returning function.
How to fix it
- Use
PERFORM expr;to evaluate and discard results. - Use
SELECT … INTO var;to capture a single-row result. - Use
RETURN QUERY SELECT …;to return rows from a set-returning function.
Related & next steps
Reference: PostgreSQL 18 Section 43.5 “Basic Statements”.
Thanks — noted. This helps keep the database accurate.