From 3522d0eaba5a976f09a48810dd25dff6ab3565df Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Sun, 22 Jul 2018 14:58:01 -0700 Subject: [PATCH] Deduplicate "invalid input syntax" messages for various types. Previously a lot of the error messages referenced the type in the error message itself. That requires that the message is translated separately for each type. Note that currently a few smallint cases continue to reference the integer, rather than smallint, type. A later patch will create a separate routine for 16bit input. Author: Andres Freund Discussion: https://postgr.es/m/20180707200158.wpqkd7rjr4jxq5g7@alap3.anarazel.de --- contrib/dblink/expected/dblink.out | 2 +- contrib/postgres_fdw/expected/postgres_fdw.out | 8 ++++---- doc/src/sgml/xtypes.sgml | 4 ++-- src/backend/utils/adt/int8.c | 4 ++-- src/backend/utils/adt/numutils.c | 12 ++++++------ src/backend/utils/adt/timestamp.c | 4 ++-- .../plpython/expected/plpython_subtransaction.out | 4 ++-- src/pl/plpython/expected/plpython_types.out | 2 +- src/pl/tcl/expected/pltcl_subxact.out | 6 +++--- src/test/regress/expected/aggregates.out | 2 +- src/test/regress/expected/alter_table.out | 2 +- src/test/regress/expected/copy2.out | 2 +- src/test/regress/expected/int2.out | 14 +++++++------- src/test/regress/expected/int4.out | 14 +++++++------- src/test/regress/expected/int8.out | 10 +++++----- src/test/regress/expected/plpgsql.out | 4 ++-- src/test/regress/expected/select_parallel.out | 2 +- src/test/regress/expected/timestamptz.out | 2 +- src/test/regress/regress.c | 4 ++-- src/tutorial/complex.c | 4 ++-- 20 files changed, 53 insertions(+), 53 deletions(-) diff --git a/contrib/dblink/expected/dblink.out b/contrib/dblink/expected/dblink.out index dfd49b937e..6ceabb453c 100644 --- a/contrib/dblink/expected/dblink.out +++ b/contrib/dblink/expected/dblink.out @@ -1154,7 +1154,7 @@ FROM dblink_fetch('myconn','error_cursor', 1) AS t(i int); SELECT * FROM dblink_fetch('myconn','error_cursor', 1) AS t(i int); -ERROR: invalid input syntax for integer: "not an int" +ERROR: invalid input syntax for type integer: "not an int" -- Make sure that the local settings have retained their values in spite -- of shenanigans on the connection. SHOW datestyle; diff --git a/contrib/postgres_fdw/expected/postgres_fdw.out b/contrib/postgres_fdw/expected/postgres_fdw.out index fc2c51c9d0..f5498c62bd 100644 --- a/contrib/postgres_fdw/expected/postgres_fdw.out +++ b/contrib/postgres_fdw/expected/postgres_fdw.out @@ -4087,16 +4087,16 @@ DROP FUNCTION f_test(int); -- =================================================================== ALTER FOREIGN TABLE ft1 ALTER COLUMN c8 TYPE int; SELECT * FROM ft1 WHERE c1 = 1; -- ERROR -ERROR: invalid input syntax for integer: "foo" +ERROR: invalid input syntax for type integer: "foo" CONTEXT: column "c8" of foreign table "ft1" SELECT ft1.c1, ft2.c2, ft1.c8 FROM ft1, ft2 WHERE ft1.c1 = ft2.c1 AND ft1.c1 = 1; -- ERROR -ERROR: invalid input syntax for integer: "foo" +ERROR: invalid input syntax for type integer: "foo" CONTEXT: column "c8" of foreign table "ft1" SELECT ft1.c1, ft2.c2, ft1 FROM ft1, ft2 WHERE ft1.c1 = ft2.c1 AND ft1.c1 = 1; -- ERROR -ERROR: invalid input syntax for integer: "foo" +ERROR: invalid input syntax for type integer: "foo" CONTEXT: whole-row reference to foreign table "ft1" SELECT sum(c2), array_agg(c8) FROM ft1 GROUP BY c8; -- ERROR -ERROR: invalid input syntax for integer: "foo" +ERROR: invalid input syntax for type integer: "foo" CONTEXT: processing expression at position 2 in select list ALTER FOREIGN TABLE ft1 ALTER COLUMN c8 TYPE user_enum; -- =================================================================== diff --git a/doc/src/sgml/xtypes.sgml b/doc/src/sgml/xtypes.sgml index 29747a0873..186e287529 100644 --- a/doc/src/sgml/xtypes.sgml +++ b/doc/src/sgml/xtypes.sgml @@ -86,8 +86,8 @@ complex_in(PG_FUNCTION_ARGS) if (sscanf(str, " ( %lf , %lf )", &x, &y) != 2) ereport(ERROR, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), - errmsg("invalid input syntax for complex: \"%s\"", - str))); + errmsg("invalid input syntax for type %s: \"%s\"", + "complex", str))); result = (Complex *) palloc(sizeof(Complex)); result->x = x; diff --git a/src/backend/utils/adt/int8.c b/src/backend/utils/adt/int8.c index 73798e7796..49f32a8b3d 100644 --- a/src/backend/utils/adt/int8.c +++ b/src/backend/utils/adt/int8.c @@ -121,8 +121,8 @@ invalid_syntax: if (!errorOK) ereport(ERROR, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), - errmsg("invalid input syntax for integer: \"%s\"", - str))); + errmsg("invalid input syntax for type %s: \"%s\"", + "bigint", str))); return false; } diff --git a/src/backend/utils/adt/numutils.c b/src/backend/utils/adt/numutils.c index b5439f497c..fb46f692e3 100644 --- a/src/backend/utils/adt/numutils.c +++ b/src/backend/utils/adt/numutils.c @@ -48,8 +48,8 @@ pg_atoi(const char *s, int size, int c) if (*s == 0) ereport(ERROR, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), - errmsg("invalid input syntax for integer: \"%s\"", - s))); + errmsg("invalid input syntax for type %s: \"%s\"", + "integer", s))); errno = 0; l = strtol(s, &badp, 10); @@ -58,8 +58,8 @@ pg_atoi(const char *s, int size, int c) if (s == badp) ereport(ERROR, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), - errmsg("invalid input syntax for integer: \"%s\"", - s))); + errmsg("invalid input syntax for type %s: \"%s\"", + "integer", s))); switch (size) { @@ -102,8 +102,8 @@ pg_atoi(const char *s, int size, int c) if (*badp && *badp != c) ereport(ERROR, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), - errmsg("invalid input syntax for integer: \"%s\"", - s))); + errmsg("invalid input syntax for type %s: \"%s\"", + "integer", s))); return (int32) l; } diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c index b98036f200..9a481f6eb9 100644 --- a/src/backend/utils/adt/timestamp.c +++ b/src/backend/utils/adt/timestamp.c @@ -480,8 +480,8 @@ parse_sane_timezone(struct pg_tm *tm, text *zone) if (isdigit((unsigned char) *tzname)) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("invalid input syntax for numeric time zone: \"%s\"", - tzname), + errmsg("invalid input syntax for type %s: \"%s\"", + "numeric time zone", tzname), errhint("Numeric time zones must have \"-\" or \"+\" as first character."))); rt = DecodeTimezone(tzname, &tz); diff --git a/src/pl/plpython/expected/plpython_subtransaction.out b/src/pl/plpython/expected/plpython_subtransaction.out index b38cde8d2d..069f0992ab 100644 --- a/src/pl/plpython/expected/plpython_subtransaction.out +++ b/src/pl/plpython/expected/plpython_subtransaction.out @@ -43,7 +43,7 @@ SELECT * FROM subtransaction_tbl; TRUNCATE subtransaction_tbl; SELECT subtransaction_test('SPI'); -ERROR: spiexceptions.InvalidTextRepresentation: invalid input syntax for integer: "oops" +ERROR: spiexceptions.InvalidTextRepresentation: invalid input syntax for type integer: "oops" LINE 1: INSERT INTO subtransaction_tbl VALUES ('oops') ^ QUERY: INSERT INTO subtransaction_tbl VALUES ('oops') @@ -95,7 +95,7 @@ SELECT * FROM subtransaction_tbl; TRUNCATE subtransaction_tbl; SELECT subtransaction_ctx_test('SPI'); -ERROR: spiexceptions.InvalidTextRepresentation: invalid input syntax for integer: "oops" +ERROR: spiexceptions.InvalidTextRepresentation: invalid input syntax for type integer: "oops" LINE 1: INSERT INTO subtransaction_tbl VALUES ('oops') ^ QUERY: INSERT INTO subtransaction_tbl VALUES ('oops') diff --git a/src/pl/plpython/expected/plpython_types.out b/src/pl/plpython/expected/plpython_types.out index eda965a9e0..98b89b7d5c 100644 --- a/src/pl/plpython/expected/plpython_types.out +++ b/src/pl/plpython/expected/plpython_types.out @@ -684,7 +684,7 @@ CREATE FUNCTION test_type_conversion_array_mixed2() RETURNS int[] AS $$ return [123, 'abc'] $$ LANGUAGE plpythonu; SELECT * FROM test_type_conversion_array_mixed2(); -ERROR: invalid input syntax for integer: "abc" +ERROR: invalid input syntax for type integer: "abc" CONTEXT: while creating return value PL/Python function "test_type_conversion_array_mixed2" CREATE FUNCTION test_type_conversion_mdarray_malformed() RETURNS int[] AS $$ diff --git a/src/pl/tcl/expected/pltcl_subxact.out b/src/pl/tcl/expected/pltcl_subxact.out index 4393f4acf6..5e19bbbc63 100644 --- a/src/pl/tcl/expected/pltcl_subxact.out +++ b/src/pl/tcl/expected/pltcl_subxact.out @@ -71,9 +71,9 @@ SELECT * FROM subtransaction_tbl; TRUNCATE subtransaction_tbl; SELECT pltcl_wrapper('SELECT subtransaction_ctx_test(''SPI'')'); - pltcl_wrapper -------------------------------------------------- - ERROR: invalid input syntax for integer: "oops" + pltcl_wrapper +------------------------------------------------------ + ERROR: invalid input syntax for type integer: "oops" (1 row) SELECT * FROM subtransaction_tbl; diff --git a/src/test/regress/expected/aggregates.out b/src/test/regress/expected/aggregates.out index a120dd83f7..5e21622754 100644 --- a/src/test/regress/expected/aggregates.out +++ b/src/test/regress/expected/aggregates.out @@ -1674,7 +1674,7 @@ LINE 1: select rank(3) within group (order by stringu1,stringu2) fro... ^ HINT: To use the hypothetical-set aggregate rank, the number of hypothetical direct arguments (here 1) must match the number of ordering columns (here 2). select rank('fred') within group (order by x) from generate_series(1,5) x; -ERROR: invalid input syntax for integer: "fred" +ERROR: invalid input syntax for type integer: "fred" LINE 1: select rank('fred') within group (order by x) from generate_... ^ select rank('adam'::text collate "C") within group (order by x collate "POSIX") diff --git a/src/test/regress/expected/alter_table.out b/src/test/regress/expected/alter_table.out index 37440f6aec..0218c2c362 100644 --- a/src/test/regress/expected/alter_table.out +++ b/src/test/regress/expected/alter_table.out @@ -1113,7 +1113,7 @@ select * from def_test; -- set defaults to an incorrect type: this should fail alter table def_test alter column c1 set default 'wrong_datatype'; -ERROR: invalid input syntax for integer: "wrong_datatype" +ERROR: invalid input syntax for type integer: "wrong_datatype" alter table def_test alter column c2 set default 20; -- set defaults on a non-existent column: this should fail alter table def_test alter column c3 set default 30; diff --git a/src/test/regress/expected/copy2.out b/src/test/regress/expected/copy2.out index e606a5fda4..eb9e4b9774 100644 --- a/src/test/regress/expected/copy2.out +++ b/src/test/regress/expected/copy2.out @@ -33,7 +33,7 @@ COPY x (a, b, c, d, e, d, c) from stdin; ERROR: column "d" specified more than once -- missing data: should fail COPY x from stdin; -ERROR: invalid input syntax for integer: "" +ERROR: invalid input syntax for type integer: "" CONTEXT: COPY x, line 1, column a: "" COPY x from stdin; ERROR: missing data for column "e" diff --git a/src/test/regress/expected/int2.out b/src/test/regress/expected/int2.out index 3ea4ed93a0..a4ec2738cd 100644 --- a/src/test/regress/expected/int2.out +++ b/src/test/regress/expected/int2.out @@ -6,7 +6,7 @@ INSERT INTO INT2_TBL(f1) VALUES ('0 '); INSERT INTO INT2_TBL(f1) VALUES (' 1234 '); INSERT INTO INT2_TBL(f1) VALUES (' -1234'); INSERT INTO INT2_TBL(f1) VALUES ('34.5'); -ERROR: invalid input syntax for integer: "34.5" +ERROR: invalid input syntax for type integer: "34.5" LINE 1: INSERT INTO INT2_TBL(f1) VALUES ('34.5'); ^ -- largest and smallest values @@ -18,27 +18,27 @@ ERROR: value "100000" is out of range for type smallint LINE 1: INSERT INTO INT2_TBL(f1) VALUES ('100000'); ^ INSERT INTO INT2_TBL(f1) VALUES ('asdf'); -ERROR: invalid input syntax for integer: "asdf" +ERROR: invalid input syntax for type integer: "asdf" LINE 1: INSERT INTO INT2_TBL(f1) VALUES ('asdf'); ^ INSERT INTO INT2_TBL(f1) VALUES (' '); -ERROR: invalid input syntax for integer: " " +ERROR: invalid input syntax for type integer: " " LINE 1: INSERT INTO INT2_TBL(f1) VALUES (' '); ^ INSERT INTO INT2_TBL(f1) VALUES ('- 1234'); -ERROR: invalid input syntax for integer: "- 1234" +ERROR: invalid input syntax for type integer: "- 1234" LINE 1: INSERT INTO INT2_TBL(f1) VALUES ('- 1234'); ^ INSERT INTO INT2_TBL(f1) VALUES ('4 444'); -ERROR: invalid input syntax for integer: "4 444" +ERROR: invalid input syntax for type integer: "4 444" LINE 1: INSERT INTO INT2_TBL(f1) VALUES ('4 444'); ^ INSERT INTO INT2_TBL(f1) VALUES ('123 dt'); -ERROR: invalid input syntax for integer: "123 dt" +ERROR: invalid input syntax for type integer: "123 dt" LINE 1: INSERT INTO INT2_TBL(f1) VALUES ('123 dt'); ^ INSERT INTO INT2_TBL(f1) VALUES (''); -ERROR: invalid input syntax for integer: "" +ERROR: invalid input syntax for type integer: "" LINE 1: INSERT INTO INT2_TBL(f1) VALUES (''); ^ SELECT '' AS five, * FROM INT2_TBL; diff --git a/src/test/regress/expected/int4.out b/src/test/regress/expected/int4.out index 372fd4d94c..bda7a8daef 100644 --- a/src/test/regress/expected/int4.out +++ b/src/test/regress/expected/int4.out @@ -6,7 +6,7 @@ INSERT INTO INT4_TBL(f1) VALUES (' 0 '); INSERT INTO INT4_TBL(f1) VALUES ('123456 '); INSERT INTO INT4_TBL(f1) VALUES (' -123456'); INSERT INTO INT4_TBL(f1) VALUES ('34.5'); -ERROR: invalid input syntax for integer: "34.5" +ERROR: invalid input syntax for type integer: "34.5" LINE 1: INSERT INTO INT4_TBL(f1) VALUES ('34.5'); ^ -- largest and smallest values @@ -18,27 +18,27 @@ ERROR: value "1000000000000" is out of range for type integer LINE 1: INSERT INTO INT4_TBL(f1) VALUES ('1000000000000'); ^ INSERT INTO INT4_TBL(f1) VALUES ('asdf'); -ERROR: invalid input syntax for integer: "asdf" +ERROR: invalid input syntax for type integer: "asdf" LINE 1: INSERT INTO INT4_TBL(f1) VALUES ('asdf'); ^ INSERT INTO INT4_TBL(f1) VALUES (' '); -ERROR: invalid input syntax for integer: " " +ERROR: invalid input syntax for type integer: " " LINE 1: INSERT INTO INT4_TBL(f1) VALUES (' '); ^ INSERT INTO INT4_TBL(f1) VALUES (' asdf '); -ERROR: invalid input syntax for integer: " asdf " +ERROR: invalid input syntax for type integer: " asdf " LINE 1: INSERT INTO INT4_TBL(f1) VALUES (' asdf '); ^ INSERT INTO INT4_TBL(f1) VALUES ('- 1234'); -ERROR: invalid input syntax for integer: "- 1234" +ERROR: invalid input syntax for type integer: "- 1234" LINE 1: INSERT INTO INT4_TBL(f1) VALUES ('- 1234'); ^ INSERT INTO INT4_TBL(f1) VALUES ('123 5'); -ERROR: invalid input syntax for integer: "123 5" +ERROR: invalid input syntax for type integer: "123 5" LINE 1: INSERT INTO INT4_TBL(f1) VALUES ('123 5'); ^ INSERT INTO INT4_TBL(f1) VALUES (''); -ERROR: invalid input syntax for integer: "" +ERROR: invalid input syntax for type integer: "" LINE 1: INSERT INTO INT4_TBL(f1) VALUES (''); ^ SELECT '' AS five, * FROM INT4_TBL; diff --git a/src/test/regress/expected/int8.out b/src/test/regress/expected/int8.out index ed0bd34221..35e3b3ff81 100644 --- a/src/test/regress/expected/int8.out +++ b/src/test/regress/expected/int8.out @@ -10,11 +10,11 @@ INSERT INTO INT8_TBL VALUES(+4567890123456789,'4567890123456789'); INSERT INTO INT8_TBL VALUES('+4567890123456789','-4567890123456789'); -- bad inputs INSERT INTO INT8_TBL(q1) VALUES (' '); -ERROR: invalid input syntax for integer: " " +ERROR: invalid input syntax for type bigint: " " LINE 1: INSERT INTO INT8_TBL(q1) VALUES (' '); ^ INSERT INTO INT8_TBL(q1) VALUES ('xxx'); -ERROR: invalid input syntax for integer: "xxx" +ERROR: invalid input syntax for type bigint: "xxx" LINE 1: INSERT INTO INT8_TBL(q1) VALUES ('xxx'); ^ INSERT INTO INT8_TBL(q1) VALUES ('3908203590239580293850293850329485'); @@ -26,15 +26,15 @@ ERROR: value "-1204982019841029840928340329840934" is out of range for type big LINE 1: INSERT INTO INT8_TBL(q1) VALUES ('-1204982019841029840928340... ^ INSERT INTO INT8_TBL(q1) VALUES ('- 123'); -ERROR: invalid input syntax for integer: "- 123" +ERROR: invalid input syntax for type bigint: "- 123" LINE 1: INSERT INTO INT8_TBL(q1) VALUES ('- 123'); ^ INSERT INTO INT8_TBL(q1) VALUES (' 345 5'); -ERROR: invalid input syntax for integer: " 345 5" +ERROR: invalid input syntax for type bigint: " 345 5" LINE 1: INSERT INTO INT8_TBL(q1) VALUES (' 345 5'); ^ INSERT INTO INT8_TBL(q1) VALUES (''); -ERROR: invalid input syntax for integer: "" +ERROR: invalid input syntax for type bigint: "" LINE 1: INSERT INTO INT8_TBL(q1) VALUES (''); ^ SELECT * FROM INT8_TBL; diff --git a/src/test/regress/expected/plpgsql.out b/src/test/regress/expected/plpgsql.out index b687fbfddc..dde2cc4bd0 100644 --- a/src/test/regress/expected/plpgsql.out +++ b/src/test/regress/expected/plpgsql.out @@ -3782,7 +3782,7 @@ begin end; $$ language plpgsql; select compos(); -ERROR: invalid input syntax for integer: "(1,hello)" +ERROR: invalid input syntax for type integer: "(1,hello)" CONTEXT: PL/pgSQL function compos() while casting return value to function's return type -- test: invalid use of composite expression in scalar-returning function create or replace function compos() returns int as $$ @@ -3791,7 +3791,7 @@ begin end; $$ language plpgsql; select compos(); -ERROR: invalid input syntax for integer: "(1,hello)" +ERROR: invalid input syntax for type integer: "(1,hello)" CONTEXT: PL/pgSQL function compos() while casting return value to function's return type drop function compos(); drop type compostype; diff --git a/src/test/regress/expected/select_parallel.out b/src/test/regress/expected/select_parallel.out index cd0b94502d..2f028d1052 100644 --- a/src/test/regress/expected/select_parallel.out +++ b/src/test/regress/expected/select_parallel.out @@ -975,7 +975,7 @@ ROLLBACK TO SAVEPOINT settings; SAVEPOINT settings; SET LOCAL force_parallel_mode = 1; select stringu1::int2 from tenk1 where unique1 = 1; -ERROR: invalid input syntax for integer: "BAAAAA" +ERROR: invalid input syntax for type integer: "BAAAAA" CONTEXT: parallel worker ROLLBACK TO SAVEPOINT settings; -- test interaction with set-returning functions diff --git a/src/test/regress/expected/timestamptz.out b/src/test/regress/expected/timestamptz.out index a901fd909d..2340f30794 100644 --- a/src/test/regress/expected/timestamptz.out +++ b/src/test/regress/expected/timestamptz.out @@ -1834,7 +1834,7 @@ WITH tzs (tz) AS (VALUES -- these should fail SELECT make_timestamptz(1973, 07, 15, 08, 15, 55.33, '2'); -ERROR: invalid input syntax for numeric time zone: "2" +ERROR: invalid input syntax for type numeric time zone: "2" HINT: Numeric time zones must have "-" or "+" as first character. SELECT make_timestamptz(2014, 12, 10, 10, 10, 10, '+16'); ERROR: numeric time zone "+16" out of range diff --git a/src/test/regress/regress.c b/src/test/regress/regress.c index 97a50f30e7..6a0d5f45e8 100644 --- a/src/test/regress/regress.c +++ b/src/test/regress/regress.c @@ -148,8 +148,8 @@ widget_in(PG_FUNCTION_ARGS) if (i < NARGS) ereport(ERROR, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), - errmsg("invalid input syntax for type widget: \"%s\"", - str))); + errmsg("invalid input syntax for type %s: \"%s\"", + "widget", str))); result = (WIDGET *) palloc(sizeof(WIDGET)); result->center.x = atof(coord[0]); diff --git a/src/tutorial/complex.c b/src/tutorial/complex.c index 1b5ebc2ff0..6798a9e6ba 100644 --- a/src/tutorial/complex.c +++ b/src/tutorial/complex.c @@ -38,8 +38,8 @@ complex_in(PG_FUNCTION_ARGS) if (sscanf(str, " ( %lf , %lf )", &x, &y) != 2) ereport(ERROR, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), - errmsg("invalid input syntax for complex: \"%s\"", - str))); + errmsg("invalid input syntax for type %s: \"%s\"", + "complex", str))); result = (Complex *) palloc(sizeof(Complex)); result->x = x; -- 2.40.0