]> granicus.if.org Git - postgresql/commit
Fix corner-case behaviors in JSON/JSONB field extraction operators.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 22 Aug 2014 17:18:00 +0000 (13:18 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 22 Aug 2014 17:18:00 +0000 (13:18 -0400)
commit15247948cc19e74b20af15020b48bee4aec771e9
tree7e844d4a7015ecb94acf8d8509f83b7b514cc778
parent32d93e8c2da5387a8d5efdd4df1e5fb9bcfa9bb2
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.
doc/src/sgml/func.sgml
doc/src/sgml/json.sgml
doc/src/sgml/release-9.4.sgml
src/backend/utils/adt/jsonfuncs.c
src/test/regress/expected/json.out
src/test/regress/expected/json_1.out
src/test/regress/expected/jsonb.out
src/test/regress/expected/jsonb_1.out
src/test/regress/sql/json.sql
src/test/regress/sql/jsonb.sql