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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Fix corner-case behaviors in JSON/JSONB field extraction operato
Date: 2014-08-22 17:18:22
Message-ID: E1XKsTm-0008St-3d@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Alvaro Herrera 2014-08-22 18:30:15 pgsql: Fix outdated comment
Previous Message Andres Freund 2014-08-22 15:51:56 pgsql: Fix newly introduced misspelling of existence in pg_buffercache.