aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/backend/utils/adt/cash.c11
-rw-r--r--src/backend/utils/adt/uuid.c8
-rw-r--r--src/test/regress/expected/money.out25
-rw-r--r--src/test/regress/expected/uuid.out13
-rw-r--r--src/test/regress/sql/money.sql6
-rw-r--r--src/test/regress/sql/uuid.sql4
6 files changed, 58 insertions, 9 deletions
diff --git a/src/backend/utils/adt/cash.c b/src/backend/utils/adt/cash.c
index f7e78fa1056..32fbad2f57d 100644
--- a/src/backend/utils/adt/cash.c
+++ b/src/backend/utils/adt/cash.c
@@ -96,6 +96,7 @@ Datum
cash_in(PG_FUNCTION_ARGS)
{
char *str = PG_GETARG_CSTRING(0);
+ Node *escontext = fcinfo->context;
Cash result;
Cash value = 0;
Cash dec = 0;
@@ -209,7 +210,7 @@ cash_in(PG_FUNCTION_ARGS)
if (pg_mul_s64_overflow(value, 10, &value) ||
pg_sub_s64_overflow(value, digit, &value))
- ereport(ERROR,
+ ereturn(escontext, (Datum) 0,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("value \"%s\" is out of range for type %s",
str, "money")));
@@ -234,7 +235,7 @@ cash_in(PG_FUNCTION_ARGS)
{
/* remember we build the value in the negative */
if (pg_sub_s64_overflow(value, 1, &value))
- ereport(ERROR,
+ ereturn(escontext, (Datum) 0,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("value \"%s\" is out of range for type %s",
str, "money")));
@@ -244,7 +245,7 @@ cash_in(PG_FUNCTION_ARGS)
for (; dec < fpoint; dec++)
{
if (pg_mul_s64_overflow(value, 10, &value))
- ereport(ERROR,
+ ereturn(escontext, (Datum) 0,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("value \"%s\" is out of range for type %s",
str, "money")));
@@ -271,7 +272,7 @@ cash_in(PG_FUNCTION_ARGS)
else if (strncmp(s, csymbol, strlen(csymbol)) == 0)
s += strlen(csymbol);
else
- ereport(ERROR,
+ ereturn(escontext, (Datum) 0,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for type %s: \"%s\"",
"money", str)));
@@ -284,7 +285,7 @@ cash_in(PG_FUNCTION_ARGS)
if (sgn > 0)
{
if (value == PG_INT64_MIN)
- ereport(ERROR,
+ ereturn(escontext, (Datum) 0,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("value \"%s\" is out of range for type %s",
str, "money")));
diff --git a/src/backend/utils/adt/uuid.c b/src/backend/utils/adt/uuid.c
index 7cec9372485..e86635a4ac3 100644
--- a/src/backend/utils/adt/uuid.c
+++ b/src/backend/utils/adt/uuid.c
@@ -31,7 +31,7 @@ typedef struct
hyperLogLogState abbr_card; /* cardinality estimator */
} uuid_sortsupport_state;
-static void string_to_uuid(const char *source, pg_uuid_t *uuid);
+static void string_to_uuid(const char *source, pg_uuid_t *uuid, Node *escontext);
static int uuid_internal_cmp(const pg_uuid_t *arg1, const pg_uuid_t *arg2);
static int uuid_fast_cmp(Datum x, Datum y, SortSupport ssup);
static bool uuid_abbrev_abort(int memtupcount, SortSupport ssup);
@@ -44,7 +44,7 @@ uuid_in(PG_FUNCTION_ARGS)
pg_uuid_t *uuid;
uuid = (pg_uuid_t *) palloc(sizeof(*uuid));
- string_to_uuid(uuid_str, uuid);
+ string_to_uuid(uuid_str, uuid, fcinfo->context);
PG_RETURN_UUID_P(uuid);
}
@@ -87,7 +87,7 @@ uuid_out(PG_FUNCTION_ARGS)
* digits, is the only one used for output.)
*/
static void
-string_to_uuid(const char *source, pg_uuid_t *uuid)
+string_to_uuid(const char *source, pg_uuid_t *uuid, Node *escontext)
{
const char *src = source;
bool braces = false;
@@ -130,7 +130,7 @@ string_to_uuid(const char *source, pg_uuid_t *uuid)
return;
syntax_error:
- ereport(ERROR,
+ ereturn(escontext,,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for type %s: \"%s\"",
"uuid", source)));
diff --git a/src/test/regress/expected/money.out b/src/test/regress/expected/money.out
index fc71a72fed3..46b2eab51ab 100644
--- a/src/test/regress/expected/money.out
+++ b/src/test/regress/expected/money.out
@@ -331,6 +331,31 @@ SELECT '($123,456.78)'::money;
-$123,456.78
(1 row)
+-- test non-error-throwing API
+SELECT pg_input_is_valid('\x0001', 'money');
+ pg_input_is_valid
+-------------------
+ f
+(1 row)
+
+SELECT pg_input_error_message('\x0001', 'money');
+ pg_input_error_message
+-----------------------------------------------
+ invalid input syntax for type money: "\x0001"
+(1 row)
+
+SELECT pg_input_is_valid('192233720368547758.07', 'money');
+ pg_input_is_valid
+-------------------
+ f
+(1 row)
+
+SELECT pg_input_error_message('192233720368547758.07', 'money');
+ pg_input_error_message
+--------------------------------------------------------------
+ value "192233720368547758.07" is out of range for type money
+(1 row)
+
-- documented minimums and maximums
SELECT '-92233720368547758.08'::money;
money
diff --git a/src/test/regress/expected/uuid.out b/src/test/regress/expected/uuid.out
index 090103df48a..0f472320096 100644
--- a/src/test/regress/expected/uuid.out
+++ b/src/test/regress/expected/uuid.out
@@ -39,6 +39,19 @@ INSERT INTO guid1(guid_field) VALUES('11+11111-1111-1111-1111-111111111111');
ERROR: invalid input syntax for type uuid: "11+11111-1111-1111-1111-111111111111"
LINE 1: INSERT INTO guid1(guid_field) VALUES('11+11111-1111-1111-111...
^
+-- test non-error-throwing API
+SELECT pg_input_is_valid('11', 'uuid');
+ pg_input_is_valid
+-------------------
+ f
+(1 row)
+
+SELECT pg_input_error_message('11', 'uuid');
+ pg_input_error_message
+------------------------------------------
+ invalid input syntax for type uuid: "11"
+(1 row)
+
--inserting three input formats
INSERT INTO guid1(guid_field) VALUES('11111111-1111-1111-1111-111111111111');
INSERT INTO guid1(guid_field) VALUES('{22222222-2222-2222-2222-222222222222}');
diff --git a/src/test/regress/sql/money.sql b/src/test/regress/sql/money.sql
index 5e746286c90..cd9a089e012 100644
--- a/src/test/regress/sql/money.sql
+++ b/src/test/regress/sql/money.sql
@@ -88,6 +88,12 @@ SELECT '-9223372036854775808'::money;
SELECT '(1)'::money;
SELECT '($123,456.78)'::money;
+-- test non-error-throwing API
+SELECT pg_input_is_valid('\x0001', 'money');
+SELECT pg_input_error_message('\x0001', 'money');
+SELECT pg_input_is_valid('192233720368547758.07', 'money');
+SELECT pg_input_error_message('192233720368547758.07', 'money');
+
-- documented minimums and maximums
SELECT '-92233720368547758.08'::money;
SELECT '92233720368547758.07'::money;
diff --git a/src/test/regress/sql/uuid.sql b/src/test/regress/sql/uuid.sql
index 3bd3b357c77..37d954eda10 100644
--- a/src/test/regress/sql/uuid.sql
+++ b/src/test/regress/sql/uuid.sql
@@ -23,6 +23,10 @@ INSERT INTO guid1(guid_field) VALUES('{22222222-2222-2222-2222-222222222222 ');
INSERT INTO guid1(guid_field) VALUES('11111111-1111-1111-G111-111111111111');
INSERT INTO guid1(guid_field) VALUES('11+11111-1111-1111-1111-111111111111');
+-- test non-error-throwing API
+SELECT pg_input_is_valid('11', 'uuid');
+SELECT pg_input_error_message('11', 'uuid');
+
--inserting three input formats
INSERT INTO guid1(guid_field) VALUES('11111111-1111-1111-1111-111111111111');
INSERT INTO guid1(guid_field) VALUES('{22222222-2222-2222-2222-222222222222}');