mirror of
https://github.com/postgres/postgres.git
synced 2025-06-13 07:41:39 +03:00
Prevent NaN in jsonb/plpython transform
As ine348e7ae57
for jsonb/plperl, prevent putting a NaN into a jsonb numeric field. Tests for this had been removed in6278a2a262
, but in case they are ever resurrected: This would change the output of the test1nan() function to an error.
This commit is contained in:
@ -5,6 +5,7 @@
|
|||||||
#include "plpy_typeio.h"
|
#include "plpy_typeio.h"
|
||||||
#include "utils/jsonb.h"
|
#include "utils/jsonb.h"
|
||||||
#include "utils/fmgrprotos.h"
|
#include "utils/fmgrprotos.h"
|
||||||
|
#include "utils/numeric.h"
|
||||||
|
|
||||||
PG_MODULE_MAGIC;
|
PG_MODULE_MAGIC;
|
||||||
|
|
||||||
@ -343,6 +344,16 @@ PLyNumber_ToJsonbValue(PyObject *obj, JsonbValue *jbvNum)
|
|||||||
|
|
||||||
pfree(str);
|
pfree(str);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* jsonb doesn't allow NaN (per JSON specification), so we have to prevent
|
||||||
|
* it here explicitly. (Infinity is also not allowed in jsonb, but
|
||||||
|
* numeric_in above already catches that.)
|
||||||
|
*/
|
||||||
|
if (numeric_is_nan(num))
|
||||||
|
ereport(ERROR,
|
||||||
|
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
|
||||||
|
(errmsg("cannot convert NaN to jsonb"))));
|
||||||
|
|
||||||
jbvNum->type = jbvNumeric;
|
jbvNum->type = jbvNumeric;
|
||||||
jbvNum->val.numeric = num;
|
jbvNum->val.numeric = num;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user