SQLSTATE P0003Severity lowLab verified

Incident brief

Too many rows

A PL/pgSQL SELECT ... INTO STRICT matched more than one row. PostgreSQL raised an error instead of silently picking one of them.

Reproduced on PostgreSQL 16.14Verified 2026-07-16 (Docker lab, PostgreSQL 16.14)Reviewed by Verified against PostgreSQL 16.14 in an isolated lab environment

In 10 seconds

What
Too many rows
What triggers it
Run SELECT ... INTO STRICT against a query that matches two or more rows.
The fix
Add ORDER BY plus LIMIT 1 to the STRICT select if exactly one specific row is genuinely the right answer.
Proof
Reproduced on PostgreSQL 16.14 → A SELECT ... INTO STRICT that matched two rows was rejected with SQLSTATE P0003. The session was unaffected afterward.

The fix

What to do right now

The immediate, application-level response to this error.

  • Add ORDER BY plus LIMIT 1 to the STRICT select if exactly one specific row is genuinely the right answer.
  • Or restructure the query to aggregate or otherwise guarantee a single row, if that's the actual intent.
Fix — SQL
DO $$
DECLARE
  x int;
BEGIN
  SELECT n INTO STRICT x FROM (VALUES (1),(2)) t(n) ORDER BY n LIMIT 1;
  RAISE NOTICE 'x = %', x;
END $$;

Related & next steps

Follow the thread

Everything this error touches — jump straight to the sibling error, term, runbook, or parameter.

Verification

PG 16.14
Last verified
2026-07-16 (Docker lab, PostgreSQL 16.14)
Reviewed by
Verified against PostgreSQL 16.14 in an isolated lab environment
Audit status
reviewed