From 3c9e74f36c5cb8ab3e237d80cb21b9496d1a9b5c Mon Sep 17 00:00:00 2001
From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Thu, 21 Aug 2025 18:37:21 -0400
Subject: [PATCH v3 4/4] Mop up a few other error message style violations.

Fix a few related messages that likewise were failing to
separate errdetail from errhint.

Reported-by: Dominique Devienne <ddevienne@gmail.com>
Author: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/1756041.1754616558@sss.pgh.pa.us
---
 doc/src/sgml/sources.sgml                  |  7 ++++---
 doc/src/sgml/typeconv.sgml                 |  6 +++---
 src/backend/parser/parse_func.c            |  8 ++++----
 src/backend/parser/parse_oper.c            |  4 ++--
 src/test/regress/expected/polymorphism.out | 15 ++++++++++-----
 src/test/regress/expected/time.out         |  3 ++-
 6 files changed, 25 insertions(+), 18 deletions(-)

diff --git a/doc/src/sgml/sources.sgml b/doc/src/sgml/sources.sgml
index fa68d4d024a..5759c6f7426 100644
--- a/doc/src/sgml/sources.sgml
+++ b/doc/src/sgml/sources.sgml
@@ -153,11 +153,12 @@ ereport(ERROR,
         errmsg("function %s is not unique",
                func_signature_string(funcname, nargs,
                                      NIL, actual_arg_types)),
-        errhint("Unable to choose a best candidate function. "
-                "You might need to add explicit typecasts."));
+        errdetail("Could not choose a best candidate function."),
+        errhint("You might need to add explicit type casts."));
 </programlisting>
     This illustrates the use of format codes to embed run-time values into
-    a message text.  Also, an optional <quote>hint</quote> message is provided.
+    a message text.  Also, optional <quote>detail</quote>
+    and <quote>hint</quote> messages are provided.
     The auxiliary function calls can be written in any order, but
     conventionally <function>errcode</function>
     and <function>errmsg</function> appear first.
diff --git a/doc/src/sgml/typeconv.sgml b/doc/src/sgml/typeconv.sgml
index 44aaf284da4..1707bd884dc 100644
--- a/doc/src/sgml/typeconv.sgml
+++ b/doc/src/sgml/typeconv.sgml
@@ -465,9 +465,9 @@ try a similar case with <literal>~</literal>, we get:
 <screen>
 SELECT ~ '20' AS "negation";
 
-ERROR:  operator is not unique: ~ "unknown"
-HINT:  Could not choose a best candidate operator. You might need to add
-explicit type casts.
+ERROR:  operator is not unique: ~ unknown
+DETAIL:  Could not choose a best candidate operator.
+HINT:  You might need to add explicit type casts.
 </screen>
 This happens because the system cannot decide which of the several
 possible <literal>~</literal> operators should be preferred.  We can help
diff --git a/src/backend/parser/parse_func.c b/src/backend/parser/parse_func.c
index f666a64999c..f293a5e3f3f 100644
--- a/src/backend/parser/parse_func.c
+++ b/src/backend/parser/parse_func.c
@@ -567,8 +567,8 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
 					 errmsg("procedure %s is not unique",
 							func_signature_string(funcname, nargs, argnames,
 												  actual_arg_types)),
-					 errhint("Could not choose a best candidate procedure. "
-							 "You might need to add explicit type casts."),
+					 errdetail("Could not choose a best candidate procedure."),
+					 errhint("You might need to add explicit type casts."),
 					 parser_errposition(pstate, location)));
 		else
 			ereport(ERROR,
@@ -576,8 +576,8 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
 					 errmsg("function %s is not unique",
 							func_signature_string(funcname, nargs, argnames,
 												  actual_arg_types)),
-					 errhint("Could not choose a best candidate function. "
-							 "You might need to add explicit type casts."),
+					 errdetail("Could not choose a best candidate function."),
+					 errhint("You might need to add explicit type casts."),
 					 parser_errposition(pstate, location)));
 	}
 	else
diff --git a/src/backend/parser/parse_oper.c b/src/backend/parser/parse_oper.c
index f9e18270489..a480dc05760 100644
--- a/src/backend/parser/parse_oper.c
+++ b/src/backend/parser/parse_oper.c
@@ -633,8 +633,8 @@ op_error(ParseState *pstate, List *op,
 				(errcode(ERRCODE_AMBIGUOUS_FUNCTION),
 				 errmsg("operator is not unique: %s",
 						op_signature_string(op, arg1, arg2)),
-				 errhint("Could not choose a best candidate operator. "
-						 "You might need to add explicit type casts."),
+				 errdetail("Could not choose a best candidate operator."),
+				 errhint("You might need to add explicit type casts."),
 				 parser_errposition(pstate, location)));
 	else
 		ereport(ERROR,
diff --git a/src/test/regress/expected/polymorphism.out b/src/test/regress/expected/polymorphism.out
index 6ac00488103..758f75b3d89 100644
--- a/src/test/regress/expected/polymorphism.out
+++ b/src/test/regress/expected/polymorphism.out
@@ -1210,7 +1210,8 @@ select dfunc();  -- fail: which dfunc should be called? int or text
 ERROR:  function dfunc() is not unique
 LINE 1: select dfunc();
                ^
-HINT:  Could not choose a best candidate function. You might need to add explicit type casts.
+DETAIL:  Could not choose a best candidate function.
+HINT:  You might need to add explicit type casts.
 select dfunc('Hi');  -- ok
    dfunc   
 -----------
@@ -1249,17 +1250,20 @@ select dfunc();  -- fail
 ERROR:  function dfunc() is not unique
 LINE 1: select dfunc();
                ^
-HINT:  Could not choose a best candidate function. You might need to add explicit type casts.
+DETAIL:  Could not choose a best candidate function.
+HINT:  You might need to add explicit type casts.
 select dfunc(1);  -- fail
 ERROR:  function dfunc(integer) is not unique
 LINE 1: select dfunc(1);
                ^
-HINT:  Could not choose a best candidate function. You might need to add explicit type casts.
+DETAIL:  Could not choose a best candidate function.
+HINT:  You might need to add explicit type casts.
 select dfunc(1, 2);  -- fail
 ERROR:  function dfunc(integer, integer) is not unique
 LINE 1: select dfunc(1, 2);
                ^
-HINT:  Could not choose a best candidate function. You might need to add explicit type casts.
+DETAIL:  Could not choose a best candidate function.
+HINT:  You might need to add explicit type casts.
 select dfunc(1, 2, 3);  -- ok
  dfunc 
 -------
@@ -1378,7 +1382,8 @@ select dfunc(1);  -- fail
 ERROR:  function dfunc(integer) is not unique
 LINE 1: select dfunc(1);
                ^
-HINT:  Could not choose a best candidate function. You might need to add explicit type casts.
+DETAIL:  Could not choose a best candidate function.
+HINT:  You might need to add explicit type casts.
 -- but this works since the ambiguous functions aren't preferred anyway
 select dfunc('Hi');
  dfunc 
diff --git a/src/test/regress/expected/time.out b/src/test/regress/expected/time.out
index 4247fae9412..765adeb6e51 100644
--- a/src/test/regress/expected/time.out
+++ b/src/test/regress/expected/time.out
@@ -157,7 +157,8 @@ SELECT f1 + time '00:01' AS "Illegal" FROM TIME_TBL;
 ERROR:  operator is not unique: time without time zone + time without time zone
 LINE 1: SELECT f1 + time '00:01' AS "Illegal" FROM TIME_TBL;
                   ^
-HINT:  Could not choose a best candidate operator. You might need to add explicit type casts.
+DETAIL:  Could not choose a best candidate operator.
+HINT:  You might need to add explicit type casts.
 --
 -- test EXTRACT
 --
-- 
2.43.7

