diff --git a/src/backend/utils/adt/tid.c b/src/backend/utils/adt/tid.c index 9257886f1da..a97873f91ba 100644 --- a/src/backend/utils/adt/tid.c +++ b/src/backend/utils/adt/tid.c @@ -73,7 +73,7 @@ tidin(PG_FUNCTION_ARGS) errno = 0; cvt = strtoul(coord[0], &badp, 10); - if (errno || *badp != DELIM) + if (badp == coord[0] || errno || *badp != DELIM) ereturn(escontext, (Datum) 0, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), errmsg("invalid input syntax for type %s: \"%s\"", @@ -95,8 +95,7 @@ tidin(PG_FUNCTION_ARGS) #endif cvt = strtoul(coord[1], &badp, 10); - if (errno || *badp != RDELIM || - cvt > USHRT_MAX) + if (badp == coord[1] || errno || *badp != RDELIM || cvt > USHRT_MAX) ereturn(escontext, (Datum) 0, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), errmsg("invalid input syntax for type %s: \"%s\"", diff --git a/src/test/regress/expected/tid.out b/src/test/regress/expected/tid.out index 3497a77688b..45cc61fb1ca 100644 --- a/src/test/regress/expected/tid.out +++ b/src/test/regress/expected/tid.out @@ -17,6 +17,14 @@ SELECT '(1,65536)'::tid; -- error ERROR: invalid input syntax for type tid: "(1,65536)" LINE 1: SELECT '(1,65536)'::tid; ^ +SELECT '(,1)'::tid; -- error +ERROR: invalid input syntax for type tid: "(,1)" +LINE 1: SELECT '(,1)'::tid; + ^ +SELECT '(1,)'::tid; -- error +ERROR: invalid input syntax for type tid: "(1,)" +LINE 1: SELECT '(1,)'::tid; + ^ -- Also try it with non-error-throwing API SELECT pg_input_is_valid('(0)', 'tid'); pg_input_is_valid diff --git a/src/test/regress/sql/tid.sql b/src/test/regress/sql/tid.sql index c0a70be5cbd..51d00b92074 100644 --- a/src/test/regress/sql/tid.sql +++ b/src/test/regress/sql/tid.sql @@ -8,6 +8,8 @@ SELECT SELECT '(4294967296,1)'::tid; -- error SELECT '(1,65536)'::tid; -- error +SELECT '(,1)'::tid; -- error +SELECT '(1,)'::tid; -- error -- Also try it with non-error-throwing API SELECT pg_input_is_valid('(0)', 'tid');