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

Commit40f52b1

Browse files
committed
Prevent NaN in jsonb/plpython transform
As ine348e7a for jsonb/plperl, preventputting a NaN into a jsonb numeric field.Tests for this had been removed in6278a2a, but in case they are everresurrected: This would change the output of the test1nan() function toan error.
1 parent0996e4b commit40f52b1

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

‎contrib/jsonb_plpython/jsonb_plpython.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include"plpy_typeio.h"
66
#include"utils/jsonb.h"
77
#include"utils/fmgrprotos.h"
8+
#include"utils/numeric.h"
89

910
PG_MODULE_MAGIC;
1011

@@ -343,6 +344,16 @@ PLyNumber_ToJsonbValue(PyObject *obj, JsonbValue *jbvNum)
343344

344345
pfree(str);
345346

347+
/*
348+
* jsonb doesn't allow NaN (per JSON specification), so we have to prevent
349+
* it here explicitly. (Infinity is also not allowed in jsonb, but
350+
* numeric_in above already catches that.)
351+
*/
352+
if (numeric_is_nan(num))
353+
ereport(ERROR,
354+
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
355+
(errmsg("cannot convert NaN to jsonb"))));
356+
346357
jbvNum->type=jbvNumeric;
347358
jbvNum->val.numeric=num;
348359

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp