pgsql: Fix corner-case behaviors in JSON/JSONB field extraction operato - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Fix corner-case behaviors in JSON/JSONB field extraction operato
Date
Msg-id E1XKsTm-0008St-3d@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Fix corner-case behaviors in JSON/JSONB field extraction operators.

Cause the path extraction operators to return their lefthand input,
not NULL, if the path array has no elements.  This seems more consistent
since the case ought to correspond to applying the simple extraction
operator (->) zero times.

Cause other corner cases in field/element/path extraction to return NULL
rather than failing.  This behavior is arguably more useful than throwing
an error, since it allows an expression index using these operators to be
built even when not all values in the column are suitable for the
extraction being indexed.  Moreover, we already had multiple
inconsistencies between the path extraction operators and the simple
extraction operators, as well as inconsistencies between the JSON and
JSONB code paths.  Adopt a uniform rule of returning NULL rather than
throwing an error when the JSON input does not have a structure that
permits the request to be satisfied.

Back-patch to 9.4.  Update the release notes to list this as a behavior
change since 9.3.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/41dd50e84df39e31595f3472b0cb6d00f63b3f99

Modified Files
--------------
doc/src/sgml/func.sgml                |    6 +-
doc/src/sgml/json.sgml                |    3 -
doc/src/sgml/release-9.4.sgml         |   33 ++
src/backend/utils/adt/jsonfuncs.c     |  575 +++++++++++++++++----------------
src/test/regress/expected/json.out    |  170 +++++++++-
src/test/regress/expected/json_1.out  |  170 +++++++++-
src/test/regress/expected/jsonb.out   |  224 +++++++++++--
src/test/regress/expected/jsonb_1.out |  224 +++++++++++--
src/test/regress/sql/json.sql         |   12 +
src/test/regress/sql/jsonb.sql        |   12 +
10 files changed, 1060 insertions(+), 369 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Fix corner-case behaviors in JSON/JSONB field extraction operato
Next
From: Alvaro Herrera
Date:
Subject: pgsql: Fix outdated comment