From 6bc91e3dfb0b0fb74cbf21d2a8b43c46604c9516 Mon Sep 17 00:00:00 2001 From: Jeevan Chalke Date: Wed, 11 Nov 2026 18:22:19 +0900 Subject: [PATCH v4 1/2] plpgsql: Clarify the LIMIT 1 example in the too-many-rows hint. The hint for queries returning more than one row suggested using LIMIT 1, but it was also shown for commands such as UPDATE ... RETURNING, which do not support that clause. Reword the hint to use LIMIT 1 with SELECT as an example, retaining concrete advice for SELECT queries without suggesting that LIMIT 1 can be used with every command. Author: Jeevan Chalke Reviewed-by: Fujii Masao Discussion: https://postgr.es/m/CAHGQGwH2xDa7CqHkKZfiWQ9+waBdUm8Vh6Br2XNMAiG3vi-hQQ@mail.gmail.com --- src/pl/plpgsql/src/pl_exec.c | 2 +- src/test/regress/expected/plpgsql.out | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/pl/plpgsql/src/pl_exec.c b/src/pl/plpgsql/src/pl_exec.c index 915f0adde2d..7fc35033aad 100644 --- a/src/pl/plpgsql/src/pl_exec.c +++ b/src/pl/plpgsql/src/pl_exec.c @@ -4538,7 +4538,7 @@ exec_stmt_execsql(PLpgSQL_execstate *estate, (errcode(ERRCODE_TOO_MANY_ROWS), errmsg("query returned more than one row"), errdetail ? errdetail_internal("parameters: %s", errdetail) : 0, - errhint("Make sure the query returns a single row, or use LIMIT 1."))); + errhint("Make sure the query returns a single row, for example by using LIMIT 1 with SELECT."))); } /* Put the first result row into the target */ exec_move_row(estate, target, tuptab->vals[0], tuptab->tupdesc); diff --git a/src/test/regress/expected/plpgsql.out b/src/test/regress/expected/plpgsql.out index b37b2abaf80..55325ea3b87 100644 --- a/src/test/regress/expected/plpgsql.out +++ b/src/test/regress/expected/plpgsql.out @@ -2732,7 +2732,7 @@ begin end$$ language plpgsql; select stricttest(); ERROR: query returned more than one row -HINT: Make sure the query returns a single row, or use LIMIT 1. +HINT: Make sure the query returns a single row, for example by using LIMIT 1 with SELECT. CONTEXT: PL/pgSQL function stricttest() line 5 at SQL statement create or replace function stricttest() returns void as $$ declare x record; @@ -2806,7 +2806,7 @@ begin end$$ language plpgsql; select stricttest(); ERROR: query returned more than one row -HINT: Make sure the query returns a single row, or use LIMIT 1. +HINT: Make sure the query returns a single row, for example by using LIMIT 1 with SELECT. CONTEXT: PL/pgSQL function stricttest() line 5 at SQL statement create or replace function stricttest() returns void as $$ declare x record; @@ -2886,7 +2886,7 @@ end$$ language plpgsql; select stricttest(); ERROR: query returned more than one row DETAIL: parameters: p1 = '2', p3 = 'foo' -HINT: Make sure the query returns a single row, or use LIMIT 1. +HINT: Make sure the query returns a single row, for example by using LIMIT 1 with SELECT. CONTEXT: PL/pgSQL function stricttest() line 8 at SQL statement create or replace function stricttest() returns void as $$ declare x record; @@ -2897,7 +2897,7 @@ begin end$$ language plpgsql; select stricttest(); ERROR: query returned more than one row -HINT: Make sure the query returns a single row, or use LIMIT 1. +HINT: Make sure the query returns a single row, for example by using LIMIT 1 with SELECT. CONTEXT: PL/pgSQL function stricttest() line 5 at SQL statement create or replace function stricttest() returns void as $$ declare x record; @@ -2945,7 +2945,7 @@ begin end$$ language plpgsql; select stricttest(); ERROR: query returned more than one row -HINT: Make sure the query returns a single row, or use LIMIT 1. +HINT: Make sure the query returns a single row, for example by using LIMIT 1 with SELECT. CONTEXT: PL/pgSQL function stricttest() line 10 at SQL statement reset plpgsql.print_strict_params; create or replace function stricttest() returns void as $$ @@ -2963,7 +2963,7 @@ end$$ language plpgsql; select stricttest(); ERROR: query returned more than one row DETAIL: parameters: p1 = '2', p3 = 'foo' -HINT: Make sure the query returns a single row, or use LIMIT 1. +HINT: Make sure the query returns a single row, for example by using LIMIT 1 with SELECT. CONTEXT: PL/pgSQL function stricttest() line 10 at SQL statement -- test warnings and errors set plpgsql.extra_warnings to 'all'; @@ -3096,7 +3096,7 @@ begin end; $$; WARNING: query returned more than one row -HINT: Make sure the query returns a single row, or use LIMIT 1. +HINT: Make sure the query returns a single row, for example by using LIMIT 1 with SELECT. set plpgsql.extra_errors to 'too_many_rows'; do $$ declare x int; @@ -3105,7 +3105,7 @@ begin end; $$; ERROR: query returned more than one row -HINT: Make sure the query returns a single row, or use LIMIT 1. +HINT: Make sure the query returns a single row, for example by using LIMIT 1 with SELECT. CONTEXT: PL/pgSQL function inline_code_block line 4 at SQL statement reset plpgsql.extra_errors; reset plpgsql.extra_warnings; -- 2.56.0