Diagnostic Queries
Symptoms
A set-returning function (SRF) was used in a WHERE clause, which is not allowed. PostgreSQL raises SQLSTATE 0A000 (feature_not_supported).
- An SRF (e.g.
generate_series,unnest) appeared in WHERE. - SRFs belong in FROM, not in row-filtering predicates.
- Common when filtering against expanded sets.
What the server log shows
ERROR: set-returning functions are not allowed in WHERE
Why PostgreSQL raises this — what the manual says
As Section 9.25 Set Returning Functions explains:
A set-returning function was placed where only a scalar value is allowed, such as a WHERE or HAVING clause or an aggregate argument; set-returning functions are permitted in the SELECT list or in the FROM clause (as a table function), so rewrite the query using a LATERAL join or a subquery in FROM.
A WHERE predicate must evaluate to a single boolean per candidate row. A set-returning function produces multiple rows, which has no defined meaning as a row filter, so PostgreSQL rejects it with 0A000.
Common causes
- Calling
unnest()/generate_series()directly in WHERE. - Trying to filter membership against an expanded set inline.
How to fix it
- Move the SRF to the FROM clause (e.g. a
LATERALjoin) and filter on its output. - Use
= ANY(array)orIN (subquery)for membership tests. - Rewrite to join against the expanded set.
Related & next steps
Reference: PostgreSQL 18 — Set Returning Functions.
Thanks — noted. This helps keep the database accurate.