Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc1b9e1e

Browse files
committed
Add numeric_int8_opt_error() to optionally suppress errors
This matches the existing numeric_int4_opt_error() (see commit16d489b). It will be used by a future JSON-related patch, whichwants to report errors in its own way and thus does not want theinternal functions to throw any error.Author: Jeevan Chalke <jeevan.chalke@enterprisedb.com>Discussion:https://www.postgresql.org/message-id/flat/CAM2+6=XjTyqrrqHAOj80r0wVQxJSxc0iyib9bPC55uFO9VKatg@mail.gmail.com
1 parentd4e66a3 commitc1b9e1e

File tree

2 files changed

+44
-16
lines changed

2 files changed

+44
-16
lines changed

‎src/backend/utils/adt/numeric.c‎

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4430,35 +4430,62 @@ int8_numeric(PG_FUNCTION_ARGS)
44304430
PG_RETURN_NUMERIC(int64_to_numeric(val));
44314431
}
44324432

4433-
4434-
Datum
4435-
numeric_int8(PG_FUNCTION_ARGS)
4433+
int64
4434+
numeric_int8_opt_error(Numericnum,bool*have_error)
44364435
{
4437-
Numericnum=PG_GETARG_NUMERIC(0);
44384436
NumericVarx;
44394437
int64result;
44404438

4439+
if (have_error)
4440+
*have_error= false;
4441+
44414442
if (NUMERIC_IS_SPECIAL(num))
44424443
{
4443-
if (NUMERIC_IS_NAN(num))
4444-
ereport(ERROR,
4445-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4446-
errmsg("cannot convert NaN to %s","bigint")));
4444+
if (have_error)
4445+
{
4446+
*have_error= true;
4447+
return0;
4448+
}
44474449
else
4448-
ereport(ERROR,
4449-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4450-
errmsg("cannot convert infinity to %s","bigint")));
4450+
{
4451+
if (NUMERIC_IS_NAN(num))
4452+
ereport(ERROR,
4453+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4454+
errmsg("cannot convert NaN to %s","bigint")));
4455+
else
4456+
ereport(ERROR,
4457+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4458+
errmsg("cannot convert infinity to %s","bigint")));
4459+
}
44514460
}
44524461

4453-
/* Convert to variable format and thence to int8 */
4462+
/* Convert to variable format, then convert to int8 */
44544463
init_var_from_num(num,&x);
44554464

44564465
if (!numericvar_to_int64(&x,&result))
4457-
ereport(ERROR,
4458-
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
4459-
errmsg("bigint out of range")));
4466+
{
4467+
if (have_error)
4468+
{
4469+
*have_error= true;
4470+
return0;
4471+
}
4472+
else
4473+
{
4474+
ereport(ERROR,
4475+
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
4476+
errmsg("bigint out of range")));
4477+
}
4478+
}
4479+
4480+
returnresult;
4481+
}
4482+
4483+
Datum
4484+
numeric_int8(PG_FUNCTION_ARGS)
4485+
{
4486+
Numericnum=PG_GETARG_NUMERIC(0);
44604487

4461-
PG_RETURN_INT64(result);
4488+
PG_RETURN_INT64(numeric_int8_opt_error(num,NULL));
44624489
}
44634490

44644491

‎src/include/utils/numeric.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,6 @@ extern Numeric numeric_div_opt_error(Numeric num1, Numeric num2,
101101
externNumericnumeric_mod_opt_error(Numericnum1,Numericnum2,
102102
bool*have_error);
103103
externint32numeric_int4_opt_error(Numericnum,bool*have_error);
104+
externint64numeric_int8_opt_error(Numericnum,bool*have_error);
104105

105106
#endif/* _PG_NUMERIC_H_ */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp