#include "plpy_typeio.h"
#include "utils/jsonb.h"
#include "utils/fmgrprotos.h"
+#include "utils/numeric.h"
PG_MODULE_MAGIC;
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->val.numeric = num;