Subject: Re: not fully correct error message

From: Tom Lane <[email-masked]>
Date: Sat, 03 Jan 2026 14:16:20 -0500

Andreas Karlsson <[email-masked]> writes:
> On 1/3/26 7:03 PM, Tom Lane wrote:
>> Yeah, I like just adding "or procedure" and calling it good.
>> I do not think we need a regression test, either ...

> Yeah, let's keep it simple.

>> Poking around, I also found this:
>> src/backend/commands/wait.c:                              errdetail("WAIT FOR cannot be executed from a function or a procedure or within a transaction with an isolation level higher than READ COMMITTED."));
>> which is also not great grammar.  What do you think of "WAIT FOR
>> cannot be executed from a function or procedure, nor within a
>> transaction with an isolation level higher than READ COMMITTED." ?

> Much better!

Putting that all together, and fixing affected regression tests
(yes, this code was covered already), I get the attached.

			regards, tom lane

diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c
index 842faa44232..c857e23552f 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -3695,7 +3695,8 @@ PreventInTransactionBlock(bool isTopLevel, const char *stmtType)
 		ereport(ERROR,
 				(errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
 		/* translator: %s represents an SQL statement name */
-				 errmsg("%s cannot be executed from a function", stmtType)));
+				 errmsg("%s cannot be executed from a function or procedure",
+						stmtType)));
 
 	/* If we got past IsTransactionBlock test, should be in default state */
 	if (CurrentTransactionState->blockState != TBLOCK_DEFAULT &&
diff --git a/src/backend/commands/wait.c b/src/backend/commands/wait.c
index d43dfd642d6..e4509fffe06 100644
--- a/src/backend/commands/wait.c
+++ b/src/backend/commands/wait.c
@@ -131,8 +131,8 @@ ExecWaitStmt(ParseState *pstate, WaitStmt *stmt, DestReceiver *dest)
 	if (HaveRegisteredOrActiveSnapshot())
 		ereport(ERROR,
 				errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
-				errmsg("WAIT FOR must be only called without an active or registered snapshot"),
-				errdetail("WAIT FOR cannot be executed from a function or a procedure or within a transaction with an isolation level higher than READ COMMITTED."));
+				errmsg("WAIT FOR must be called without an active or registered snapshot"),
+				errdetail("WAIT FOR cannot be executed from a function or procedure, nor within a transaction with an isolation level higher than READ COMMITTED."));
 
 	/*
 	 * As the result we should hold no snapshot, and correspondingly our xmin
diff --git a/src/test/recovery/t/049_wait_for_lsn.pl b/src/test/recovery/t/049_wait_for_lsn.pl
index e0ddb06a2f0..5f415b9af51 100644
--- a/src/test/recovery/t/049_wait_for_lsn.pl
+++ b/src/test/recovery/t/049_wait_for_lsn.pl
@@ -102,7 +102,7 @@ $node_standby->psql(
 	"BEGIN ISOLATION LEVEL REPEATABLE READ; SELECT 1; WAIT FOR LSN '${lsn3}';",
 	stderr => \$stderr);
 ok( $stderr =~
-	  /WAIT FOR must be only called without an active or registered snapshot/,
+	  /WAIT FOR must be called without an active or registered snapshot/,
 	"get an error when running in a transaction with an isolation level higher than REPEATABLE READ"
 );
 
@@ -122,7 +122,7 @@ $node_standby->psql(
 	"SELECT pg_wal_replay_wait_wrap('${lsn3}');",
 	stderr => \$stderr);
 ok( $stderr =~
-	  /WAIT FOR must be only called without an active or registered snapshot/,
+	  /WAIT FOR must be called without an active or registered snapshot/,
 	"get an error when running within another function");
 
 # 5. Check parameter validation error cases on standby before promotion
diff --git a/src/test/regress/expected/subscription.out b/src/test/regress/expected/subscription.out
index 327d1e7731f..b3eccd8afe3 100644
--- a/src/test/regress/expected/subscription.out
+++ b/src/test/regress/expected/subscription.out
@@ -357,7 +357,7 @@ END;
 CREATE FUNCTION func() RETURNS VOID AS
 $$ ALTER SUBSCRIPTION regress_testsub SET PUBLICATION mypub WITH (refresh = true) $$ LANGUAGE SQL;
 SELECT func();
-ERROR:  ALTER SUBSCRIPTION with refresh cannot be executed from a function
+ERROR:  ALTER SUBSCRIPTION with refresh cannot be executed from a function or procedure
 CONTEXT:  SQL function "func" statement 1
 ALTER SUBSCRIPTION regress_testsub DISABLE;
 ALTER SUBSCRIPTION regress_testsub SET (slot_name = NONE);

---

From: Andreas Karlsson <[email-masked]>
Date: Sat, 3 Jan 2026 22:12:26 +0100

> (yes, this code was covered already), I get the attached.

That looks good to me.

Andreas

---

From: Tom Lane <[email-masked]>
Date: Sat, 03 Jan 2026 17:19:18 -0500

> That looks good to me.

Pushed.

			regards, tom lane