aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTeodor Sigaev <teodor@sigaev.ru>2016-02-11 18:11:11 +0300
committerTeodor Sigaev <teodor@sigaev.ru>2016-02-11 18:11:11 +0300
commit07d25a964b2fb78169a4a34c6f6893736f69903a (patch)
treeb4be32ede25bcdb111a0a802b53ce8e1c8c3723b /src
parenta455878d99561d4b199915ed7a7fb02f5e621710 (diff)
downloadpostgresql-07d25a964b2fb78169a4a34c6f6893736f69903a.tar.gz
postgresql-07d25a964b2fb78169a4a34c6f6893736f69903a.zip
Improve error reporting in format()
Clarify invalid format conversion type error message and add hint. Author: Jim Nasby
Diffstat (limited to 'src')
-rw-r--r--src/backend/utils/adt/varlena.c15
-rw-r--r--src/test/regress/expected/text.out9
2 files changed, 15 insertions, 9 deletions
diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c
index f61e41ed7f1..94599cc508f 100644
--- a/src/backend/utils/adt/varlena.c
+++ b/src/backend/utils/adt/varlena.c
@@ -4788,7 +4788,8 @@ text_reverse(PG_FUNCTION_ARGS)
if (++(ptr) >= (end_ptr)) \
ereport(ERROR, \
(errcode(ERRCODE_INVALID_PARAMETER_VALUE), \
- errmsg("unterminated format specifier"))); \
+ errmsg("unterminated format() type specifier"), \
+ errhint("For a single \"%%\" use \"%%%%\"."))); \
} while (0)
/*
@@ -4920,8 +4921,9 @@ text_format(PG_FUNCTION_ARGS)
if (strchr("sIL", *cp) == NULL)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("unrecognized conversion type specifier \"%c\"",
- *cp)));
+ errmsg("unrecognized format() type specifier \"%c\"",
+ *cp),
+ errhint("For a single \"%%\" use \"%%%%\".")));
/* If indirect width was specified, get its value */
if (widthpos >= 0)
@@ -4932,7 +4934,7 @@ text_format(PG_FUNCTION_ARGS)
if (arg >= nargs)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("too few arguments for format")));
+ errmsg("too few arguments for format()")));
/* Get the value and type of the selected argument */
if (!funcvariadic)
@@ -5040,8 +5042,9 @@ text_format(PG_FUNCTION_ARGS)
/* should not get here, because of previous check */
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("unrecognized conversion type specifier \"%c\"",
- *cp)));
+ errmsg("unrecognized format() type specifier \"%c\"",
+ *cp),
+ errhint("For a single \"%%\" use \"%%%%\".")));
break;
}
}
diff --git a/src/test/regress/expected/text.out b/src/test/regress/expected/text.out
index 1587046d95a..a74b9cebd6c 100644
--- a/src/test/regress/expected/text.out
+++ b/src/test/regress/expected/text.out
@@ -211,7 +211,8 @@ ERROR: too few arguments for format
select format('Hello %s');
ERROR: too few arguments for format
select format('Hello %x', 20);
-ERROR: unrecognized conversion type specifier "x"
+ERROR: unrecognized format() type specifier "x"
+HINT: For a single "%" use "%%".
-- check literal and sql identifiers
select format('INSERT INTO %I VALUES(%L,%L)', 'mytab', 10, 'Hello');
format
@@ -263,9 +264,11 @@ ERROR: format specifies argument 0, but arguments are numbered from 1
select format('%*0$s', 'Hello');
ERROR: format specifies argument 0, but arguments are numbered from 1
select format('%1$', 1);
-ERROR: unterminated format specifier
+ERROR: unterminated format() type specifier
+HINT: For a single "%" use "%%".
select format('%1$1', 1);
-ERROR: unterminated format specifier
+ERROR: unterminated format() type specifier
+HINT: For a single "%" use "%%".
-- check mix of positional and ordered placeholders
select format('Hello %s %1$s %s', 'World', 'Hello again');
format